VS Task Runner Explorer - Node Sass could not find

2019-05-23 06:53发布

问题:

When opening the Visual Studio Task Runner Explorer, the gulpfile.js fails to load and this error is emitted in the Output window.

Failed to run "C:\DATA\Git\MyApp\MyBiz.MyApp\MyBiz.MyApp.WebsiteCore\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
C:\DATA\Git\MyApp\MyBiz.MyApp\MyBiz.MyApp.WebsiteCore\node_modules\node-sass\lib\binding.js:15
      throw new Error(errors.missingBinary());
      ^
Error: Missing binding C:\DATA\Git\MyApp\MyBiz.MyApp\MyBiz.MyApp.WebsiteCore\node_modules\node-sass\vendor\win32-ia32-47\binding.node
Node Sass could not find a binding for your current environment: Windows 32-bit with Node.js 5.x
Found bindings for the following environments:
  - Windows 64-bit with Node.js 6.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to build the binding for your current environment.
    at module.exports (C:\DATA\Git\MyApp\MyBiz.MyApp\MyBiz.MyApp.WebsiteCore\node_modules\node-sass\lib\binding.js:15:13)
    at Object.<anonymous> (C:\DATA\Git\MyApp\MyBiz.MyApp\MyBiz.MyApp.WebsiteCore\node_modules\node-sass\lib\index.js:14:35)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (C:\DATA\Git\MyApp\MyBiz.MyApp\MyBiz.MyApp.WebsiteCore\node_modules\gulp-sass\index.js:187:21)
    at Module._compile (module.js:397:26)

Running gulp runs the tasks and my SASS compiles fine.

I tried reinstalling node, I have also ensured only one npm runnable is in the Windows path and I've deleted the node_modules folder and run npm install a few times, also tried npm rebuild node-sass.

All these millions of cool new front-end tools and libraries seem to be hugely broadening the surface of "things to go wrong", not very productive at all compared to previous projects.

Luke

回答1:

Configure VS to use the newer version of node.

Find instructions by Ryan Hayes at Synchronize Node.JS Install Version with Visual Studio 2015

Snippets from the instructions are below in case the link goes stale.

I updated Node.JS outside of Visual Studio, but since VS uses its own install that is separate from any outside installation, you can potentially run into a node_modules package dependency issue where one version of npm installs a package (which makes it rely on that version of Node/npm), and then you can’t run commands in the other version (they break). Specifically, I had an issue with node-sass and windows bindings. The solution was to point Visual Studio to the version of Node.JS that I had already set up externally to Visual Studio.

  1. First, find the Node.js installation you already have and use at the command line.

I had installed nodejs at C:\Program Files (x86)\nodejs\.

  1. Go to Tools > Options in Visual Studio 2015.
  2. In this dialog, go to Projects and Solutions > External Web Tools to open the dialog that manages all of the 3rd party tools used within VS. This is where Node.js is pointed to.
  3. Add an entry at the top to the path to the node.js directory to force Visual Studio to use that version instead.


回答2:

For Visual Studio 2017 the category name is different. Instead of External Web Tools it is now called "Web Package management"

Visual Studio 2017 External Tools npm Not working