nodejs-maven-plugin bundles npm 1.4.9 that seems to ignore npm install's --prefix directory

Description

The plugin is configured with these settings:

<npmVersion>6.4.1</npmVersion> <nodeJsVersion>10.15.2</nodeJsVersion> <nodeJsDirectory>${project.basedir}/nodejsplugin-cache</nodeJsDirectory>

Running under Windows, the following happens:

The plugin downloads npm 1.4.9. It uses npm 1.4.9 to install the npm specified in the pom.xml, i.e. 6.4.1.

[INFO] --- nodejs-maven-plugin:2.0.4:run (default-cli) @ nolio-core-ui --- [INFO] Installing specified npm version 6.4.1 [INFO] Running process: C:\project\nodejsplugin-cache\v-10.15.2\node.exe C:\project\nodejsplugin-cache\v-10.15.2\npm\bin\npm-cli.js install --prefix C:\project\nodejsplugin-cache npm@6.4.1 [INFO] [nodejs] npm http GET https://registry.npmjs.org/npm [INFO] [nodejs] npm http 304 https://registry.npmjs.org/npm [WARNING] [nodejs] npm WARN prefer global npm@6.4.1 should be installed with -g [WARNING] [nodejs] npm WARN package.json path-is-inside@1.0.2 No README data [WARNING] [nodejs] npm WARN package.json sorted-object@2.0.1 No README data [WARNING] [nodejs] npm WARN package.json punycode@1.4.1 punycode is also the name of a node core module. [WARNING] [nodejs] npm WARN package.json string_decoder@1.1.1 string_decoder is also the name of a node core module. [INFO] [nodejs] npm@6.4.1 node_modules\npm [INFO] Running process: C:\project\nodejsplugin-cache\v-10.15.2\node.exe C:\project\nodejsplugin-cache\node_modules\npm\bin\npm-cli.js install --prefix C:\project\nodejsplugin-cache\ grunt-cli [INFO] [nodejs] internal/modules/cjs/loader.js:583 [INFO] [nodejs] throw err; [INFO] [nodejs] ^ [INFO] [nodejs] [INFO] [nodejs] Error: Cannot find module 'C:\project\nodejsplugin-cache\node_modules\npm\bin\npm-cli.js' [INFO] [nodejs] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15) [INFO] [nodejs] at Function.Module._load (internal/modules/cjs/loader.js:507:25) [INFO] [nodejs] at Function.Module.runMain (internal/modules/cjs/loader.js:742:12) [INFO] [nodejs] at startup (internal/bootstrap/node.js:283:19) [INFO] [nodejs] at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3) [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------

What happens is, the plugin tries to install the new npm into --prefix directory, but without the -g option, the old npm doesn't install where you tell it to, it will instead walk up the hierarchy looking for a node_modules/ directory or a package.json file.

Branching from this commit:

commit 56810260cfe6ea8d7b9bb573ecff1eaba7fd2bff Author: sseifert <sseifert@pro-vision.de> Date: Wed Feb 8 23:15:46 2017 +0100

I changed AbstractNodeJsMojo.java:

npmInstallTask.setArguments(new String[] { "--prefix", nodeJsDirectory.getAbsolutePath(), "-g", "npm@" + npmVersion });

To pass the "-g" argument and now it works as expected.

Attachments

1
  • 04 Mar 2019, 05:29 PM

Activity

Show:

Yuri Geinish May 10, 2019 at 9:42 AM

Thank you! Everything's tip-top now.

Stefan Seifert April 4, 2019 at 11:14 PM

this is fixed in Node.js Maven Plugin 3.0.0

please note the new version 1.2.0 of Maven NodeJS Proxy is required because we now support for windows the same type of installation as on the other platforms (using a ZIP file containing both NodeJS and the bundles NPM version) - which is available since Node 6.3.0.

specifying the NPM version is now optional - if not defined the bundles NPM version is used.

Yuri Geinish March 4, 2019 at 5:37 PM

Attached

.

If you run npm149.bat install --prefix cache npm@6.4.1, which is what the nodejs plugin does, you'll see npm@6.4.1 gets installed into node_modules/, not into cache/node_modules/.

If you try the same with -g, it will install into cache/node_modules/.

Stefan Seifert March 4, 2019 at 4:04 PM

thanks for reporting this.

is was unable to reproduce the problem when applying the parameters you mentioned to a test project.
do you have a test project to reproduce the behavior?

Fixed

Details

Assignee

Reporter

Components

Priority

Created March 1, 2019 at 4:21 PM
Updated August 21, 2019 at 8:03 AM
Resolved April 4, 2019 at 11:14 PM