gulp integration in Visual Studio 2017 not working

亡梦爱人 提交于 2021-01-26 19:07:49

问题


I'm attempting to get gulp integration into Visual Studio 2017. It's working on the command line. The Task Runner Explorer in VS2017 is telling me Failed to load. See output window.

The Output Window is telling me the following:

Failed to run "<ProjectPath>\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
<ProjectPath>\node_modules\node-sass\lib\binding.js:15
      throw new Error(errors.missingBinary());
      ^
Error: Missing binding <ProjectPath>\node_modules\node-sass\vendor\win32-x64-47\binding.node
Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 5.x
Found bindings for the following environments:
  - Windows 64-bit with Node.js 8.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.

I attempt to run npm rebuild node-sass --force, only to be told Error: Can't find Python executable "C:\Python36\python.EXE", you can set the PYTHON env variable., which I confirmed existed.

I'm not sure how much farther I want to go down this rabbit hole. It appears to be a VS issue since everything works as expected on the command line. I'd like to get the gulp integration with VS working correctly.


回答1:


Point your VS tools to the node installation on your path.

I can see in the error that there a version discrepancy between 5.x and 8.x - with VS likely being the older one (since it ships with pre-packaged and outdated node) and is taking execution precedence with the default setup.

I'm guessing you installed node-sass via your 8.x (external command line) instance but VS is trying to execute your gulp tasks via your VS's internal 5.x. node-sass leverages node-gyp to build a binary via installation scripts, and there will be incompatibilities across versions. In other words, this package, and many others that build binaries, are specifically tailored to the version of node it was installed against. To summarize, everything in node_modules/.bin is built against 8.x but is actually running on 5.x when you do so through Visual Studio.

Fear not, this is easily solved. Check out this answer for some historical context on this long running issue that many face. Basically, you want $(PATH) to be at the top of this list so your OS installation is always used...

Once you do this (just to be safe) - blow away node_modules, reinstall, and happy coding. VS really needs to stop shipping with pinned versions of node...




回答2:


I ran into this problem on both Visual Studio 2017 and 2019. Apparently my Node install wasn't registered in the PATH variable (and I don't have permission to modify this on my work machine), so I manually added the link to Node at C:\Program Files\nodejs, moved that to the top location and that worked for me.




回答3:


This drove me nuts until I found one more missing thing. Even if you configured everything as in the other answers you can get the same error, possibly if your user folder is not on the same drive as where Node is installed. Then also add %APPDATA%\npm to the external tools paths so globally installed Node tools will be found too.

So all in all the external tools config in VS should contain these two paths first, in this order:

  1. C:\Program Files\NodeJS (or where you have Node installed).
  2. %APPDATA%\npm

For me without #2 everything was working from the command line everywhere but not in VS. With it added everything now works in VS too.



来源:https://stackoverflow.com/questions/48737556/gulp-integration-in-visual-studio-2017-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!