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

Created on 11 Jun 2018  Â·  19Comments  Â·  Source: nodejs/node-gyp

  • 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:UsersvertangelxAppDataRoamingnpmnode_modulesnpmnode_modulesnode_modulesnode-gypbinnode-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

Most helpful comment

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 Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-binnode-gyp.cmd" in an editor
  3. removed that extra "node_modules' from 2nd line to read as 'node "%~dp0....node-gypbinnode-gyp.js" %*'
  4. Tested with 'node-gyp --help' in command prompt
    And it worked !

All 19 comments

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 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?

When you uninstall node, is C:UsersvertangelxAppDataRoamingnpm gone too? If not, remove it manually.

@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!

Same issue as vertangelx with message
Cannot find module 'C:Program Filesnodejsnode_modulesnpmnode_modulesnode_modulesnode-gypbinnode-gyp.js'

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

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 Filesnodejsnode_modulesnpmnode_modulesnode_modulesnode-gypbinnode-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.

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.

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

@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 Filesnodejsnode_modulesnpmnode_modules
• Copy node-gyp folder from above location and paste it in below location.
C:UsersAppDataRoamingnpmnode_modulesnpmnode_modules

@Nandansv did not work for me ;/

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.

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

C:Windowssystem32>node-gyp rebuild

C:Windowssystem32>if not defined npm_config_node_gyp (node "C:Program Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-bin\....node_modulesnode-gypbinnode-gyp.js" rebuild ) else (node "" rebuild )
internal/modules/cjs/loader.js:584
throw err;
^

Error: Cannot find module 'C:Program Filesnodejsnode_modulesnpmnode_modulesnode_modulesnode-gypbinnode-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)

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

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_modulesnode_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:ProgramFilesnodejsnode_modulesnpmnode_modulesnode_modules
node-gypbinnode-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:Usersvote1AppDataRoaming"

So a full rebuild instruction could also be:

C:Usersvote1AppDataRoaming 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:Windowssystem32>node-gyp rebuild

C:Windowssystem32>if not defined npm_config_node_gyp (node "C:Program
Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-bin....node_modulesnode-gypbinnode-gyp.js"
rebuild ) else (node "" rebuild )
internal/modules/cjs/loader.js:584
throw err;
^

Error: Cannot find module 'C:Program
Filesnodejsnode_modulesnpmnode_modulesnode_modulesnode-gypbinnode-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
.

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 Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-binnode-gyp.cmd" in an editor
  3. removed that extra "node_modules' from 2nd line to read as 'node "%~dp0....node-gypbinnode-gyp.js" %*'
  4. Tested with 'node-gyp --help' in command prompt
    And it worked !

@samahudin It works to me! 😄

@samahudin .. Great Observation !

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 Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-binnode-gyp.cmd" in an editor
  3. removed that extra "node_modules' from 2nd line to read as 'node "%~dp0....node-gypbinnode-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?

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

In my case, my path is: C:Program
Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-bin

Basically, on my drive there are 2 confusing folders under
nodejsnode_modulesnpm and they are node_modulesnode_modules, and
node_modulesnpm-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_modulesnode_modules" becomes
"node_modulesnpm-lifecycle".

The path then reflects this exact folder structure: C:Program
Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-bin

Hope that makes sense.

On Wed, Jun 12, 2019 at 12:39 AM James Barrett notifications@github.com
wrote:

For me it threw an error like below :
Error: Cannot find module 'C:Program
Filesnodejsnode_modulesnpmnode_modulesnode_modulesnode-gypbinnode-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
    Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-binnode-gyp.cmd"
    in an editor
  3. removed that extra "node_modules' from 2nd line to read as 'node
    "%~dp0....node-gypbinnode-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
.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Flimm picture Flimm  Â·  3Comments

chen4393 picture chen4393  Â·  3Comments

jplatte picture jplatte  Â·  3Comments

zghbyslzf picture zghbyslzf  Â·  3Comments

gengjiawen picture gengjiawen  Â·  3Comments