node-gyp icon indicating copy to clipboard operation
node-gyp copied to clipboard

Cannot find module `...\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js`

Open vertangelx opened this issue 8 years ago • 19 comments

  • Node Version: v8.11.2 (node), v6.1.0 (npm)
  • Platform: Windows 10 x64
  • Compiler: ?
  • Module: -
Verbose output (from npm or node-gyp):
(base) C:\Users\vertangelx\Desktop\cosmic>node-gyp

(base) C:\Users\vertangelx\Desktop\cosmic>if not defined npm_config_node_gyp (node "C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js"  )  else (node ""  )
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

(base) C:\Users\vertangelx\Desktop\cosmic>npm uninstall -g node-gyp
removed 105 packages in 0.848s

(base) C:\Users\vertangelx\Desktop\cosmic>npm install -g node-gyp
C:\Users\vertangelx\AppData\Roaming\npm\node-gyp -> C:\Users\vertangelx\AppData\Roaming\npm\node_modules\node-gyp\bin\node-gyp.js
+ [email protected]
added 105 packages from 66 contributors in 2.02s

(base) C:\Users\vertangelx\Desktop\cosmic>node-gyp

(base) C:\Users\vertangelx\Desktop\cosmic>if not defined npm_config_node_gyp (node "C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js"  )  else (node ""  )
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

(base) C:\Users\vertangelx\Desktop\cosmic>node-gyp

(base) C:\Users\vertangelx\Desktop\cosmic>if not defined npm_config_node_gyp (node "C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js"  )  else (node ""  )
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

Why does running the command node-gyp tries to look for the binary in such a strange location with repeating node_modules\npm\?

C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js

Tried uninstalling and reinstalling node-gyp but error remains.

Installed node-gyp using

npm install --global --production windows-build-tools
npm install -g node-gyp

vertangelx avatar Jun 10 '18 22:06 vertangelx

You don't need to install node-gyp yourself, it's bundled with npm. Uninstall your global copy and if it still doesn't work after that, reinstall npm.

bnoordhuis avatar Jun 11 '18 09:06 bnoordhuis

@bnoordhuis Tried your suggestion, removed the global copy of node-gyp but the same error persits

(base) C:\Users\vertangelx\Desktop\cosmic>npm uninstall -g node-gyp
removed 105 packages in 0.811s

(base) C:\Users\vertangelx\Desktop\cosmic>node-gyp

(base) C:\Users\vertangelx\Desktop\cosmic>if not defined npm_config_node_gyp (node "C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js"  )  else (node ""  )
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

Next I tried your second suggestion, used the Node .msi package for Windows to remove Node, then ran it again to install Node.

However the same error occurs when running node-gyp.

Checked the directory it is using, and node-gyp.js does exist at

C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js

but not where it was searching for

C:\Users\vertangelx\AppData\Roaming\npm\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js

image

What should I do, please?

vertangelx avatar Jun 11 '18 14:06 vertangelx

When you uninstall node, is C:\Users\vertangelx\AppData\Roaming\npm gone too? If not, remove it manually.

bnoordhuis avatar Jun 11 '18 17:06 bnoordhuis

@bnoordhuis After uninstalling node, C:\Users\vertangelx\AppData\Roaming\npm directory was not deleted. Gone ahead to delete the folder, then installed Node again.

Now when I run node-gyp in the command prompt, it seems that node-gyp is not installed.

Ran npm install -g node-gyp and everything works now! Thanks!

vertangelx avatar Jun 12 '18 00:06 vertangelx

Same issue as vertangelx with message Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'

If I uninstall node then delete the \Roaming\npm folder, won't that mean I lose all the folders inside ? There are a bunch of those which would be a pain to reinstall.

xthdraft avatar Oct 30 '18 20:10 xthdraft

Actually, I found the simplest solution is to create an extra \node_modules folder and copy the existing node-gyp folder into it. Then your c: drive will contain this: C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js'

You end up with a duplicate node-gyp folder, but at least this will prevent the error message when you run "node-gyp configure". The rest of your build will not be affected by this strategy.

xthdraft avatar Oct 31 '18 00:10 xthdraft

For those still experiencing this issue, I did this:

Uninstall everything npm. Go to /usr/local/lib/ and remove the node_modules folder completely. Make sure you have no npm or .npm folders. Next, download and install the latest node and npm from https://nodejs.org/en/. Then run npm install node-gyp -g.

This fixed it for me.

tochie avatar Nov 03 '18 21:11 tochie

Thanks for the steps @tochie, that fixed it for me as well!

pchiwan avatar Nov 06 '18 11:11 pchiwan

@bnoordhuis After uninstalling node, C:\Users\vertangelx\AppData\Roaming\npm directory was not deleted. Gone ahead to delete the folder, then installed Node again.

Now when I run node-gyp in the command prompt, it seems that node-gyp is not installed.

Ran npm install -g node-gyp and everything works now! Thanks!

Hi , It works even without uninstalling node js.. Just follow below steps. C:\Program Files\nodejs\node_modules\npm\node_modules • Copy node-gyp folder from above location and paste it in below location. C:\Users<UserName>\AppData\Roaming\npm\node_modules\npm\node_modules

Nandansv avatar Feb 21 '19 12:02 Nandansv

@Nandansv did not work for me ;/

emil-kirilov avatar Apr 04 '19 07:04 emil-kirilov

Also met this trouble on windows. Reinstalling node and removing C:\Users\username\AppData\npm helped me. And also after node installation there was not bundled node-gyp, and I had to install it by npm i -g node-gyp. Probably the root of the trouble is

npm i -g npm <maybe other modules here also play its roles in bug>

which brings chaos into directories.

Dzenly avatar Apr 06 '19 01:04 Dzenly

Hello, Can someone assist me on this one? I tried every solution said above but none solved it to my current problem. Thanks

C:\Windows\system32>node-gyp rebuild

C:\Windows\system32>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild ) internal/modules/cjs/loader.js:584 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15) at Function.Module._load (internal/modules/cjs/loader.js:508:25) at Function.Module.runMain (internal/modules/cjs/loader.js:754:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

kakkero avatar Apr 06 '19 03:04 kakkero

Installing and building a node-gyp app, you need to install some windows build tools:

*the install instructions are at: *https://www.npmjs.com/package/node-gyp

the 2 basic instructions for setting up node-gyp are:

  • npm install -g node-gyp

  • for windows: npm install --global --production windows-build-tools (do this latter from a powershell prompt)

This should install windows build tools:

*visual studio: *version 2.5.2+gebb9f26a3d [query version 1.17.1230.42073]

After doing those steps, proceed:

Building the native app

The basic steps are:

  • Set up a new folder for your addon:
  • add a binding.gyp file and 2 subfolders
    • c:\myaddon
      • binding.gyp
      • \build
      • \src
        • appname.c
      • write/edit your binding.gyp and appname.c files

Your binding.gyp file will be something like this: { "targets": [ { "target_name": "appname", "sources": [ "src/appname.c" ] } ] }

Once you have your folder structure in place, you run this from a command prompt at c:\myaddon

  • node-gyp configure build

Note: no spaces either side of "=" Also no double spaces.

The rebuild command is necessary to ensure that your addon agrees with the version of electron installed.

If the configure command complains about not finding a \node_modules\node_modules folder, you can simply create an extra \node_modules folder and copy the existing node-gyp folder into it. Then your c: drive will contain this:

C:\ProgramFiles\nodejs\node_modules\npm\node_modules\node_modules \node-gyp\bin\node-gyp.js'

location of node-gyp:

node-gyp is in your HOME directory: this is found from the APPDATA variable in ALLUSERSPROFILE

If you type process.env inside an electron devtools pane:

APPDATA: "C:\Users\vote1\AppData\Roaming"

So a full rebuild instruction could also be:

C:\Users\vote1\AppData\Roaming node-gyp rebuild --target=3.0.6 --arch=x64 --dist-url=https://atom.io/download/electron

Hope that helps. It worked for me.

On Sat, Apr 6, 2019 at 2:18 PM Kim Alfred E. Kotico < [email protected]> wrote:

Hello, Can someone assist me on this one? I tried every solution said above but none solved it to my current problem. Thanks

C:\Windows\system32>node-gyp rebuild

C:\Windows\system32>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild ) internal/modules/cjs/loader.js:584 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15) at Function.Module._load (internal/modules/cjs/loader.js:508:25) at Function.Module.runMain (internal/modules/cjs/loader.js:754:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nodejs/node-gyp/issues/1463#issuecomment-480469963, or mute the thread https://github.com/notifications/unsubscribe-auth/ADCMuiuDop08P6iRGBTkfsHZWqTniJPMks5veBITgaJpZM4Uh4-9 .

xthdraft avatar Apr 06 '19 21:04 xthdraft

For me it threw an error like below : Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js' If you also can see this line in your error stack, it seems like a packaging error. What I have done is :

  1. Found that the node_gyp is actually a level up in the directory structure
  2. Opened "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\node-gyp.cmd" in an editor
  3. removed that extra "\node_modules' from 2nd line to read as 'node "%~dp0....\node-gyp\bin\node-gyp.js" %*'
  4. Tested with 'node-gyp --help' in command prompt And it worked !

samahudin avatar Apr 12 '19 14:04 samahudin

@samahudin It works to me! 😄

tbvjaos510 avatar Apr 25 '19 00:04 tbvjaos510

@samahudin .. Great Observation !

ghost avatar May 22 '19 06:05 ghost

For me it threw an error like below : Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js' If you also can see this line in your error stack, it seems like a packaging error. What I have done is :

  1. Found that the node_gyp is actually a level up in the directory structure
  2. Opened "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\node-gyp.cmd" in an editor
  3. removed that extra "\node_modules' from 2nd line to read as 'node "%~dp0....\node-gyp\bin\node-gyp.js" %*'
  4. Tested with 'node-gyp --help' in command prompt And it worked !

I've tried this solution yet I still receive the same error which mentions the same path. In other words, the node-gyp.cmd edit isn't taking effect.

Has anyone had a similar problem and found a workaround?

jamesbarrett95 avatar Jun 11 '19 14:06 jamesbarrett95

Maybe check your path in the environmental variables section (user variables) of your win10 settings.

In my case, my path is: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\

Basically, on my drive there are 2 confusing folders under \nodejs\node_modules\npm\ and they are node_modules\node_modules, and node_modules\npm-lifecycle

My solution was to ignore the first of these, and I simply altered my path as stated above.

As you can see, the double " node_modules\node_modules" becomes "node_modules\npm-lifecycle".

The path then reflects this exact folder structure: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin

Hope that makes sense.

On Wed, Jun 12, 2019 at 12:39 AM James Barrett [email protected] wrote:

For me it threw an error like below : Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\node_modules\node-gyp\bin\node-gyp.js' If you also can see this line in your error stack, it seems like a packaging error. What I have done is :

  1. Found that the node_gyp is actually a level up in the directory structure
  2. Opened "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\node-gyp.cmd" in an editor
  3. removed that extra "\node_modules' from 2nd line to read as 'node "%~dp0....\node-gyp\bin\node-gyp.js" %*'
  4. Tested with 'node-gyp --help' in command prompt And it worked !

I've tried this solution yet I still receive the same error which mentions the same path. In other words, the node-gyp.cmd edit isn't taking effect.

Has anyone had a similar problem and found a workaround?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nodejs/node-gyp/issues/1463?email_source=notifications&email_token=AAYIZOXMVOWRL6I5R7GEZOLPZ62KFA5CNFSM4FEHR662YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXNLF7Y#issuecomment-500871935, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYIZOXUI2ZCXBTI272T7TLPZ62KFANCNFSM4FEHR66Q .

xthdraft avatar Jun 11 '19 23:06 xthdraft

Even I was facing such a problem, I just reinstalled NodeJs again and everything went perfect

huilgolAni19 avatar Jan 01 '20 06:01 huilgolAni19