VS任务运行器资源管理器 - Node Sass无法找到绑定。

7
打开 Visual Studio 任务运行器时,gulpfile.js 加载失败,此错误会在输出窗口中显示。
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)

运行gulp会执行任务,并且我的SASS编译正常。
我尝试重新安装node,确保只有一个可运行的npm在Windows路径中,并且已删除node_modules文件夹并多次运行npm install,还尝试了npm rebuild node-sass
所有这些很酷的新前端工具和库似乎极大地扩展了“出错的事情”表面,与以前的项目相比,不是非常高效。
卢克

很惭愧,我放弃了并回到了ASP.NET MVC 5 :-/ - Luke Puplett
4个回答

14

配置VS以使用更新的node版本。

查看Ryan Hayes在“将Node.JS安装版本与Visual Studio 2015同步”中的指示。

以下是指令片段,以防链接过期。

我在Visual Studio之外更新了Node.JS,但由于VS使用其自己的安装程序,与任何外部安装程序都是分开的,因此您可能会遇到一个node_modules包依赖问题,其中一个版本的npm安装了一个包(使其依赖于该版本的Node/npm),然后您不能在另一个版本中运行命令(它们会失败)。具体来说,我遇到了node-sass和windows绑定的问题。解决方案是将Visual Studio指向我已经在Visual Studio之外设置的Node.JS版本。

  1. 首先,在命令行中找到您已经安装并使用的Node.js安装位置。

我已经在C:\Program Files (x86)\nodejs\安装了nodejs。

  1. 在Visual Studio 2015中选择工具 > 选项
  2. 在此对话框中,转到项目和解决方案 > 外部Web工具以打开管理VS中使用的所有第三方工具的对话框。这就是Node.js指向的位置。
  3. 在顶部添加一个条目,指向node.js目录的路径,以强制Visual Studio使用该版本。 enter image description here

如果有人可以保证这个答案,请在评论中留言,我会接受它。 - Luke Puplett
2
@LukePuplett,我刚刚遇到了这个问题,而这个回答确实有效。 - Tom
对我来说,解决方案是确保 PATH 变量位于其他变量之前的顶部。 - JakeMc

9

工具 > 选项 > 项目和解决方案 > Web 包管理 > 外部 Web 工具 > 将 $(PATH) 移至 $(VSInstalledExternalTools) 上方。


3
这就是答案! - Rafe

1

我也在VS 2019上遇到了同样的问题。以下步骤适用于我。

工具 -> 选项 -> 项目和解决方案 -> Web包管理 -> 外部Web工具 -> 添加以下条目 C:\Program Files\nodejs -> 并将添加的移动到顶部。

enter image description here


1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接