1

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.

Gunnar
  • 383
  • 4
  • 18

2 Answers2

0

Are you sure you have gulp in the development requirements?

Try - npm install gulp --save-dev

Fraser
  • 15,275
  • 8
  • 53
  • 104
  • Thanks, would you mind explaining some more details? I'm an absolute node-noob, another company prepared the build using the Liferay IDE and i want to integragte it as a command line build. What exactly does this command you mentioned? – Gunnar Oct 12 '17 at 15:14
  • This command saves the glup module as a development dependency. If you open your packages.json you will see it has been added to the correct section. See - https://stackoverflow.com/questions/19223051/grunt-js-what-does-save-dev-mean-in-npm-install-grunt-save-dev – Fraser Oct 12 '17 at 15:20
  • I see, thank you. But did you read that the theme build works on my machine but not on another developer machine, when I zip my complete installation and unzip it there? Is your tip related to that problem? – Gunnar Oct 12 '17 at 15:23
  • well it would make sure that glup is installed as a dev dependency...chances are that the two machines have different global package settings, so the other machine is looking for a file which doesn't exist...If the first option doesn't work try - 'npm link gulp' to see if that fixes it. – Fraser Oct 12 '17 at 15:33
  • How could the other machine have different settings, when it builds the same project with my zipped node installation? (No machine here has installed anything node-related so far, and the zipped installation is to be complete, without needing to install anything after unzipping it). My suspicion is that I missed something in my zipfile because it resides outside my installation directory. The other machine also uses the same .npmrc and the same environment variables including the extended path - some commands work normal as described in the question. Thanks anyway :-) – Gunnar Oct 12 '17 at 15:50
  • The global node package directory is outside the installation directory. So yes - you haven't copied gulp. And yes It is quite possible to have a different global package location on machines by default. – Fraser Oct 12 '17 at 15:53
  • @Gunnar - ooi as you are asking if I read the question, could I ask if you have read the manual? Oviously if you are doing 'install -g' then you aren't installing into your project and so are not going to be zipping it. – Fraser Oct 12 '17 at 16:07
  • Hello again, the custom installation directory contains the node installation (unzipped win64 zipfile), the npm-packages containing the node modules and the npm-cache (like stated in the question). The complete zipfile is 7xMB large atm. The global installation is the goal, nothing should be installed in the project directory. I thought I could make this clear, sorry if not. How could the other machine have a different global package location when no node exists before and my zipfile (and .npmrc and environment variables) are used, that is what I'm trying to find out... – Gunnar Oct 12 '17 at 16:35
  • Go read the manual, honestly - if you install a package globally then it isn't installed under node_modules. It could be '/usr/local/lib/node' or '/usr/local/lib/node_modules' or '%USERPROFILE%\Application Data\npm\node_modules' or '%USERPROFILE%\Application Data\npm\node_modules' - run 'npm list -g' on each machine - do they agree? If so do they contain the same files? The answer to one is NO. – Fraser Oct 12 '17 at 16:36
  • 1
    Thank you, I'll test the list cmd tomorrow (19h here). – Gunnar Oct 12 '17 at 16:53
0

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.

Gunnar
  • 383
  • 4
  • 18