Generator-jhipster: Cannot find module '..\node_modules\npm\bin\npm-cli.js' when running "gradlew -Pprod bootRepackage"

Created on 7 Aug 2015  路  27Comments  路  Source: jhipster/generator-jhipster

I am new to this, so please bare with me. What I am doing is trying to deploy my jhipster code. For that I need to build war file. So I run the command gradlew -Pprod bootRepackage in command prompt. My project has no node_modules folder and so it is throwing error : Cannot find module '..node_modulesnpmbinnpm-cli.js' .

invalid

Most helpful comment

I solved it using the following steps

  1. manually create a folder called npm under node_modules folder of the nodejs installation
  2. Launch the nodejs installable and opt for repair option

All 27 comments

This is an NPM installation problem, not a JHipster bug.

Have a look at the NPM documentation, you have nice videos etc: https://docs.npmjs.com/

But why is it looking for node_modules folder in my project instead of the global folder where npm is installed?

If your project has no node_modules folder, it's because the install phase after generation did no succeed or you did not follow the procedure in our doc.
Run it manually:

npm install
bower install

Got It @gmarziou . Actually I created the Jhipster project on a different machine and committed the code to be run on my machine. Now node_modules folder path is in .gitignore, so not committed. Should I remove the node_modules from .gitignore and recommit or I have to run npm on my machine again?

If node_modules is not existing ./gradlew -Pprod bootRepackage executes npm install, so you should keep node_modules ignored. Which version of the generator are you using? Which operating system are you using?

All Right. I am using windows and the latest version of Jhipster: 2.19.0

I ran the following command on windows cmd: gradlew -Pprod bootRepackage. It Build Successfully but it did not generate any node_modules folder.

Okay, I can't check it now on windows. @deepu105 Can you try it? But it sounds like a npm missconfiguration.

One more thing. If I run yo jhipster:cloudfoundry from windows it gives error: The goal you specified requires a project to execute but there is no POM in this Directory. Please verify you invoked maven from the correct directory.

Now since it is supposed to be a gradle build how can we make cf understand this.
I found something here (Can we use this?): https://github.com/cloudfoundry/cf-java-client/blob/master/cloudfoundry-gradle-plugin/README.md

I've been having the same issue trying to build on Windows. I was able to figure it out. Put the following in profile_prod.gradle:

node {
    download = true
    version = '0.12.7'
}

Gradle will then download and install node and npm to the project's node_modules folder before running npm install.

For some reason Gradle is trying to use node/npm in the project's local npm_modules folder instead of what's in the PATH. This may be a bug with the Gradle node plugin, but I haven't done enough investigation to know where the problem lies for sure. See https://github.com/srs/gradle-node-plugin/issues/64

Edit: JHipster 2.20.0 requires at least node 0.12.0 but the plugin will download 0.11.10 by default, so you will need to specify the version. I updated the config to reflect this.

I will check it but it sounds like a windows specific issue.

Yeah, it works fine on Linux.

@geraldhumphries the version should be in braces (it doesn't work the other way for me):
node { version = '0.12.7' }

Anyway it still didn't resolve my issue. It downloads the npm to some location that is not node_modules in my directory and then build fails on npmInstall.

@Vistritium do you mean the quotation marks? I missed them when I was typing up the edit. I've fixed that, thanks.

Do you also have download = true within the node extension block or did you just leave it out to demonstrate the fix? Where does it download node?

@geraldhumphries
Yes I meant quotation marks.
Yes I had also download = true within the node block. To be honest I don't know where it downloaded them, console only displayed that it downloads it but it didn't say where and it did not appear in node_modules directory. When launch second time it won't display download log again so it have it downloaded somewhere.

For now I have get rid of gradle-node-plugin and use normal gradle task exec to run npm install:

task npmBuild(type: Exec){
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        commandLine 'cmd', '/c', 'npm', 'install'
    } else {
        commandLine 'npm', 'install'
    }
}
gruntBuild.dependsOn 'npmBuild'

This fix the issue for me.
Of course developer now must download his npm by himself but I don't think this is a big concern.

geraldhumphries's solution:

node {
    download = true
    version = '0.12.7'
}

gets me the dreadful bufferutil / node-gyp error:

npm ERR! [email protected] install: `node-gyp rebuild` 
npm ERR! Exit status 1
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the bufferutil package,    

npm install does not install npm in the local node_modules directory.

This is what works (for me, on Windows 7):
I copied the npm directory from the node install, to the local node_modules:

cp -r /c/Program\ Files/nodejs/node_modules/npm node_modules/npm

Then

gradle -Pprod bootRepackage

(or ./gradlew -Pprod bootRepackage)
works.

This seems like a terrible work-around, and I'd appreciate any better suggestions.

Hello. I had the same problem and installed locale npm to project

npm install npm

@jdubois someone in gitter had this issue with 2.27.1 today. Maybe worth reopening and investigating?

@geraldhumphries Hi, I had an issue too with gulp in 2.27.1. It's working with grunt.
I don't have my computer here to provide more information.

Hi, I'm having this executing gradle with liquibaseDiffChangelog. Jhipster 2.27.1.

I'm also facing this issue on 2.27.1 with Gulp, Gradle, Node 5.7, Windows 10.

@panser, thanks for that tip.

I solved it in my computer (win10) by copy the npm file(downloaded from official website) to where the problem located to. :100:

I solved it using the following steps

  1. manually create a folder called npm under node_modules folder of the nodejs installation
  2. Launch the nodejs installable and opt for repair option

If you run into trouble after @pradeep1765's great fix, remember to init your directory so that npm doesn't delete itself, unless you enjoy the catharsis of running repair after every time you install a new package.

This works for me:
go to:
C:Usersyour-userAppDataRoaming
Delete npm and npm-cache
Then
run on your console:
npm install

npm install -g npm@[version] fixed the problem

Please don't comment on an old issue.
If you think this issue still applies, please create a new ticket with proper details.

If you have a question please use Stack Overflow, and tag the question with jhipster. This helps the project to keep the issue tracker clean. Also, Stack Overflow will give your question a larger audience:

  • This will increase your chances to get an answer
  • Answers will be of higher quality, as there is a voting system
  • This will also help other users who might have the same issue, as questions are tagged and easily searchable
Was this page helpful?
0 / 5 - 0 ratings

Related issues

shivroy121 picture shivroy121  路  3Comments

kaidohallik picture kaidohallik  路  3Comments

marcelinobadin picture marcelinobadin  路  3Comments

frantzynicolas picture frantzynicolas  路  3Comments

DanielFran picture DanielFran  路  3Comments