Search code examples
node.jsgulp

Custom bundled node installation does not work on other PC


13-10-2017 - Self answered, see below, problem solved

13-10-2017 - Update added, see end of question, still unsolved

Description first, problem later:

Our team uses a prepared development environment and I want to add the node components needed for building Liferay dxp themes with the liferay theme generator.

I've installed node from the Win64-Zip-Installation, so I just unpacked it to a custom directory (win10).

I've set the Environment Variables and created the .npmrc, the prefix (npm-packages) and cache (npm-cache) also reside in the above mentioned custom directory.

I've installed additional required components via npm (gulp, yo, generator-liferay-theme, liferay-theme-tasks, liferay-theme-deps-7.0, all with -g)

So my global installation looks like this

custom directory
               |
               +--- node-v6.11.4-win-x64
               |
               +--- npm-cache
               |
               +--- npm-packages

Environment variables are set

NODE_PATH=(custom directory)\node-v6.11.4-win-x64;(custom directory)\npm-packages\node_modules
NPM_PACKAGES=(custom directory)\npm-packages

Including the Path

Path=...;(custom directory)\node-v6.11.4-win-x64;(custom directory)\npm-packages

And the .npmrc goes like

prefix=(custom directory)\npm-packages
cache=(custom directory)\npm-cache
proxy=(our proxy)
registry=http://registry.npmjs.org/
fetch-retry-mintimeout=1000
fetch-retry-maxtimeout=3000
strict-ssl=false

Building the Liferay DXP theme works on my machine - WOMM

When I zip the complete custom folder and unzip it on another developer machine (and also setting environment variables and .npmrc on the other machine), the build doesn't work.

The error message (maven antrun exec gulp.cmd) is

[exec] Error: Cannot find module '(project directory)\node_modules\gulp\bin\gulp.js'

Where "(project directory)" is my DXP theme source folder, not the above mentioned custom installation folder.

Other commands show no problems on the other machine, like for example

node -v
npm -v
npm cache ls

Also a

npm install -g yo gulp

finished quickly and showed no error.

Update

One try yesterday was to call

npm install -g yo gulp

on the other machine, this should be the only difference to the content of the zipfile.

The call

npm list -g

shows these differences on the other machine

1099a1100
>   +-- is-installed-globally@0.1.0 extraneous
1222a1224,1226
>   | +-- chalk@2.1.0 invalid
>   | | +-- ansi-styles@3.2.0 extraneous
>   | | `-- supports-color@4.4.0 extraneous

The invalid entry is a child of yo.update-notifier

Next try on the other machine

npm uninstall -g yo
npm cache clear
npm install -g yo

The new diff between my and the other machine

1211c1211
<   +-- update-notifier@2.2.0
---
>   +-- update-notifier@2.3.0
1222a1223,1225
>   | +-- chalk@2.1.0
>   | | +-- ansi-styles@3.2.0
>   | | `-- supports-color@4.4.0
1223a1227,1230
>   | +-- is-installed-globally@0.1.0
>   | | +-- global-dirs@0.1.0
>   | | `-- is-path-inside@1.0.0
>   | |   `-- path-is-inside@1.0.2
1257c1264
<   | +-- diff@3.3.1
---
>   | +-- diff@3.4.0

But the build on the other machine still throws the same error.


Solution

  • Self answering, some maven/antrun/jdk magic - I should bang my head against the wall multiple times.

    When I started testing on my colleague's machine he mentioned "I'm on jdk6 because I'm developing this and that"

    "No problem", I said, "it's not java".

    But this was the problem. Switching to jdk8 made the build work on the colleague's machine.

    Maybe I should have tested the command line build without maven, just "gulp build" on the prompt, because I guess, the jdk-problem is related to maven -> antrun/ant -> gulp and not to node and/or gulp itself (?)

    Remembering the error when using jdk6:

    [exec] Error: Cannot find module '(project directory)\node_modules\gulp\bin\gulp.js'
    

    Summary

    You can set up a zipfile containing global node installations and use it on other machines, just don't forget to

    • use no old java
    • set the environment variables and .npmrc content to match the directories you're using

    Example

    • zip contains an unzipped node installation (win64 zip from nodejs for example)
    • zip contains node-packages and node-cache
    • unzip to c:\global-node
    • set NODE_PATH=c:\global-node\node-v6.11.4-win-x64;c:\global-node\npm-packages\node_modules
    • set NPM_PACKAGES=c:\global-node\npm-packages
    • set/extend path with ";c:\global-node\node-v6.11.4-win-x64;c:\global-node\npm-packages"
    • your ~/.npmrc needs an entry prefix=c:\global-node\npm-packages
    • and an entry cache=c:\global-node\npm-cache

    And you're done with a reusable global zipped node installation.