microsoft / nodejstools

Node.js Tools for Visual Studio
http://aka.ms/explorentvs
Apache License 2.0
1.8k stars 359 forks source link

node-gyp rebuild fails in VS2015 due to wrong path #649

Closed thomas-darling closed 8 years ago

thomas-darling commented 8 years ago

Package restore in Visual Studio 2015 fails with the following:

> utf-8-validate@1.2.1 install C:\MyProject\node_modules\browser-sync\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild
C:\MyProject\node_modules\browser-sync\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate>node "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild 
npm http 200 https://registry.npmjs.org/adm-zip
npm http 200
module.js:340
    throw err;
          ^
Error: Cannot find module 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

Looks like the file path to node-gyp.js is wrong - the nearest instance of that file appears to be: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\node-gyp\bin\node-gyp.js

This issue may be a result of installing the lates Node.js Tools for Visual Studio, although I'm not sure this is the cause. I suspect it might have something to do with the flatter package folder heirachy created by the newer version of npm - maybe something have moved around in there, causing a path somewhere to now be invalid?

I'm not sure whether this is an issue in the Node.js Tools, NPM, or somewhere else - but it's consistently failing during package restore in Visual Studio. Manually running npm install in the console works perfectly though, so it appears to be specific to Visual Studio.

thomas-darling commented 8 years ago

To reproduce the issue, create a new MVC 6 project and replace the content of package.json with the following. Save the file, and watch the output in the NPM console:

{
  "name": "ASP.NET",
  "version": "0.0.0",
  "devDependencies": {
    "aurelia-bundler": "^0.1.9",
    "aurelia-tools": "^0.1.16",
    "babel": "^5.8.23",
    "browser-sync": "^2.10.0",
    "conventional-changelog": "^0.5.1",
    "del": "^2.2.0",
    "gulp": "^3.8.10",
    "gulp-babel": "^5.1.0",
    "gulp-bump": "^0.3.1",
    "gulp-changed": "^1.1.0",
    "gulp-notify": "^2.2.0",
    "gulp-plumber": "^1.0.1",
    "gulp-protractor": "^0.0.12",
    "gulp-sourcemaps": "^1.6.0",
    "isparta": "^3.1.0",
    "istanbul": "gotwarlost/istanbul#source-map",
    "jasmine-core": "^2.1.3",
    "jspm": "^0.16.15",
    "karma": "^0.13.15",
    "karma-babel-preprocessor": "^5.2.1",
    "karma-chrome-launcher": "^0.1.7",
    "karma-coverage": "douglasduteil/karma-coverage#next",
    "karma-jasmine": "^0.3.5",
    "karma-jspm": "2.0.1-beta.2",
    "merge": "^1.2.0",
    "require-dir": "^0.3.0",
    "run-sequence": "^1.1.5",
    "yargs": "^2.1.1",
    "tslint": "3.2.0-dev.1",
    "gulp-tslint": "^4.1.2",
    "gulp-typescript": "^2.10.0",
    "gulp-less": "^3.0.5",
    "less-plugin-autoprefix": "^1.5.1",
    "less-plugin-clean-css": "^1.5.1",
    "gulp-htmlmin": "^1.2.0",
    "gulp-lint-filepath": "^1.0.1"
  }
}
mousetraps commented 8 years ago

Sorry for the delayed response. This isn't related to Node.js Tools, but rather the private version of npm installed by the Web Tools component, so I'll loop in the team responsible. In the meantime... I'm not sure specifically why it's resolving improperly - perhaps it's just an old version of npm / node-gyp that had a bug - but I suggest installing the latest version of node/npm and pointing to that in the External Web Tools settings instead.

mousetraps commented 8 years ago

I chatted with the Web Tools team, and they are planning to update the default settings for the External Web Tools paths to point to $(PATH) by default, and only fall back to their privately installed versions of node, gulp, npm, etc. when it does not exist. This will enable VS to more closely mirror the CLI in the future.

Closing as this issue is unrelated to NTVS, and should be taken care of by VS2015 Update 2. In the meantime, you can simply manually adjust those settings.

AnderssonPeter commented 8 years ago

I got this issue when i try to install the npm package "gulp-zopfli" and im using VS2015 Update 3 so this issue still presists.

victor-kachesov commented 8 years ago

I got same issue when I try to install "gulp-xml-editor". I am using VS2015 Version 14.0.25422.01 Update 3. I've attached log file from Visual Studio npm-debug.log.txt

AnderssonPeter commented 8 years ago

I managed to fix this issue by installing the latest node from https://nodejs.org/en/ (i ran with the 4.* version).

Then i added the path to the newly installed node to my visual studio settings Options > Projects and Solutions > External Web Tools, and i added it between .\node_modules\.bin and $(VSINSTALLDIR)\web\External.

I might have done some configuration for node to find the c++ compilator and the python runtime but i can´t remember exactly how i did it.