Uploaded image for project: 'wcm.io Tooling'
  1. WTOOL-49

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects versions: Node.js Maven Plugin 2.0.4
    • Components: Maven
    • Labels:
      None
    • Sprint:

      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.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Stefan Seifert
                Reporter:
                Yuri Geinish
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: