为什么npm install失败并出现与node-sass相关的错误?

4

我正在处理一个继承来的Rails应用程序。我尝试运行npm install命令,但是我一直收到下面的错误。根据输出建议,我尝试运行npm rebuild node-sass,但没有帮助。我在Ubuntu 16OS X上都遇到了这个问题。

> cd client && npm install

npm WARN deprecated gulp-jscs@3.0.2: JSCS is deprecated. Switch to ESLint.
npm WARN deprecated why-did-you-update@0.0.8: Package no longer supported. Please use @welldone-software/why-did-you-render instead.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated jscs-preset-wikimedia@1.0.1: No longer maintained. We recomment migrating to ESLint with eslint-config-wikimedia.
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated core-js@1.2.7: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated nomnom@1.8.1: Package no longer supported. Contact support@npmjs.com for more info.

> railsapp@1.0.0 postinstall /Users/antarr/code/railsapp/client
> npm run build


> railsapp@1.0.0 build /Users/antarr/code/railsapp/client
> NODE_ENV=production webpack -p && NODE_ENV=production gulp build

Hash: b24f8ebb1737ed4fc3f1
Version: webpack 1.15.0
Time: 39385ms
               Asset     Size  Chunks             Chunk Names
    client.bundle.js   949 kB       0  [emitted]  client
     tools.bundle.js   903 kB       1  [emitted]  tools
client.bundle.js.map  6.62 MB       0  [emitted]  client
 tools.bundle.js.map  6.29 MB       1  [emitted]  tools
    + 913 hidden modules
/Users/antarr/code/railsapp/client/node_modules/node-sass/lib/binding.js:15
      throw new Error(errors.missingBinary());
      ^

Error: Missing binding /Users/antarr/code/railsapp/client/node_modules/node-sass/vendor/darwin-x64-48/binding.node
Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 6.x

Found bindings for the following environments:
  - OS X 64-bit with Unsupported runtime (83)

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 (/Users/antarr/code/railsapp/client/node_modules/node-sass/lib/binding.js:15:13)
    at Object.<anonymous> (/Users/antarr/code/railsapp/client/node_modules/node-sass/lib/index.js:14:35)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/antarr/code/railsapp/client/node_modules/gulp-sass/index.js:187:21)

npm ERR! Darwin 19.4.0
npm ERR! argv "/Users/antarr/.nvm/versions/node/v6.6.0/bin/node" "/Users/antarr/.nvm/versions/node/v6.6.0/bin/npm" "run" "build"
npm ERR! node v6.6.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! railsapp@1.0.0 build: `NODE_ENV=production webpack -p && NODE_ENV=production gulp build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the railsapp@1.0.0 build script 'NODE_ENV=production webpack -p && NODE_ENV=production gulp build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the railsapp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     NODE_ENV=production webpack -p && NODE_ENV=production gulp build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs railsapp
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls railsapp
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/antarr/code/railsapp/client/npm-debug.log

npm ERR! Darwin 19.4.0
npm ERR! argv "/Users/antarr/.nvm/versions/node/v6.6.0/bin/node" "/Users/antarr/.nvm/versions/node/v6.6.0/bin/npm" "install"
npm ERR! node v6.6.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! railsapp@1.0.0 postinstall: `npm run build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the railsapp@1.0.0 postinstall script 'npm run build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the railsapp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs railsapp
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls railsapp
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/antarr/code/railsapp/client/npm-debug.log

npm ERR! Darwin 19.4.0
npm ERR! argv "/Users/antarr/.nvm/versions/node/v6.6.0/bin/node" "/Users/antarr/.nvm/versions/node/v6.6.0/bin/npm" "install"
npm ERR! node v6.6.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! railsapp@1.0.0 postinstall: `cd client && npm install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the railsapp@1.0.0 postinstall script 'cd client && npm install'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the railsapp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     cd client && npm install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs railsapp
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls railsapp
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/antarr/code/railsapp/npm-debug.log

package.json:

{
  "name": "railsapp",
  "version": "1.0.0",
  "description": "...",
  "private": true,
  "engines": {
    "node": "6.6.0",
    "npm": "3.10.7"
  },
  "main": "server.js",
  "repository": {
    "type": "git",
    "url": ""
  },
  "scripts": {
    "postinstall": "cd client && npm install",
    "build": "cd client && npm run build",
    "build:dev": "cd client && npm run build:dev",
    "watch": "cd client && npm run watch",
    "gulp": "cd client && gulp default --color",
    "gulp:hot": "cd client && gulp hot --color",
    "gulp:express": "cd client && gulp express --color",
    "gulp:live": "cd client && gulp live --color",
    "start": "cd client && npm start",
    "lint": "cd client && npm run lint",
    "test": "bundle exec rake test && (cd client && npm run lint)",
    "express": "echo 'visit http://localhost:4000' && (cd client && npm start)",
    "rails": "(cd client && npm run build:dev) && rails s"
  },
  "author": "Mike R <mike@railsapp.com>",
  "bugs": {
    "url": ""
  },
  "homepage": "https://www.railsapp.com",
  "dependencies": {
    "postcss": "^7.0.30",
    "postcss-cssnext": "^3.1.0"
  }
}

添加 node-sass 后出现错误:

    + 838 hidden modules
gulp[7747]: ../src/node_contextify.cc:658:static void node::contextify::ContextifyScript::New(const v8::FunctionCallbackInfo<v8::Value>&): Assertion `args[1]->IsString()' failed.
 1: 0xa0e670 node::Abort() [gulp]
 2: 0xa0e6ee  [gulp]
 3: 0xa006df node::contextify::ContextifyScript::New(v8::FunctionCallbackInfo<v8::Value> const&) [gulp]
 4: 0xbf1fc1  [gulp]
 5: 0xbf2b52 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [gulp]
 6: 0x13da5f9  [gulp]
Aborted (core dumped)

@AjeetShah node-sass 没有被列出。 - Antarr Byrd
该文件不存在。 - Antarr Byrd
2个回答

7

您可以使用以下版本:

Node: 12,NPM: 6和node-sass: 4.12+


要解决此错误,您需要根据版本兼容性列表修复您的nodenode-sass版本。从该列表中,如果使用node-sass 4.5.3+,则最低需求为Node 8

我建议您升级到最新的LTS Node 12.16.3(包括npm6.14.4),然后使用node-sass版本4.12+这里是如何升级node和npm的方法。

要更改node-sass版本,请在您的package.json中编写此代码:"node-sass": "^4.12.0",


在添加了node-sass之后,我遇到了一个新的错误。我已经将其添加到上面了。 - Antarr Byrd
我正在使用Node 13.14.0和npm 6.14.4。 - Antarr Byrd
在删除了 node_modules 并清除缓存后,我得到了这个结果:https://gist.github.com/antarr/7d6aca45427ebb733e5b41e4e9b0b13b - Antarr Byrd
package.json 指定了 ^4.14.1 - Antarr Byrd
1
这个版本兼容性很好。你救了我! - Kheder

0
尝试清除 nodeModule 并粘贴一个 nodemodule 的副本,如果在某个地方保存为克隆。 这将帮助您找到包并使其开始工作。
对我来说就是这样起作用的。
希望对您也有帮助。

你的回答可以通过提供更多支持性信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人能够确认你的回答是否正确。你可以在帮助中心找到关于如何撰写好回答的更多信息。 - Community
你的回答可以通过提供更多的支持性信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的回答是否正确。你可以在帮助中心找到关于如何撰写好的回答的更多信息。 - undefined
这并没有真正回答问题。如果你有其他问题,可以点击提问来提出。如果你想在这个问题有新的回答时收到通知,你可以关注此问题。一旦你拥有足够的声望,你还可以添加悬赏以吸引更多关注。- 来自评论 - Wahlstrommm
这并没有真正回答问题。如果你有其他问题,你可以点击提问来提出。如果你想在这个问题有新的回答时收到通知,你可以关注这个问题。一旦你有足够的声望,你还可以添加悬赏来吸引更多的关注。- 来自评论 - undefined

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