【问题标题】:npm install throwing error in node-sassnpm install 在 node-sass 中抛出错误
【发布时间】:2018-01-17 06:07:01
【问题描述】:
node-sass@2.1.1 install /home/user/Documents/project/node_modules/node-sass
> node scripts/install.js

WARN invalid config loglevel="notice"
Can not download file from https://raw.githubusercontent.com/sass/node-sass-binaries/v2.1.1/linux-x64-node-8.2/binding.node

> node-sass@2.1.1 postinstall /home/user/Documents/project/node_modules/node-sass
> node scripts/build.js

module.js:487
    throw err;
    ^

Error: Cannot find module '/home/user/Documents/project/node_modules/node-sass/node_modules/pangyp/bin/node-gyp'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
Build failed
added 2186 packages in 42.166s

到目前为止我试过了:

  • npm 重建
  • npm 重建 node-sass
  • npm 卸载 -g node-sass
  • rm -rf 节点模块
  • 【问题讨论】:

    • 看来你需要安装node-gypnpm install -g node-gyp
    • node-sass@2.1.1 严重过时(我尝试安装它并能够重现错误);您可以尝试编辑package.json 以改用最新版本。 (删除@2.1.1)

    标签: node.js npm node-sass


    【解决方案1】:
    1. package.json 中删除“node-sass”依赖项
    2. 运行 npm 安装
    3. 运行 npm i sass
    4. 运行 npm start

    你准备好了! :)

    【讨论】:

      【解决方案2】:

      使用

      • 节点:v14.16.0
      • 节点萨斯:^4.14.1

      对我有用

      【讨论】:

        【解决方案3】:

        删除了package-lock.json,安装了Python 2.7,为python 路径添加了env variable。 跑npm install。 瞧!

        【讨论】:

          【解决方案4】:

          node-sass 根据系统中安装的节点版本具有最小的依赖性。您可以找到所需的最低版本here

          【讨论】:

            【解决方案5】:

            使用纱线运行:

            yarn add node-sass
            

            【讨论】:

              【解决方案6】:

              在 package.json 中手动添加 : "node-sass": "4.13.0"

              并在终端 npm install 中更新 package.json

              【讨论】:

                【解决方案7】:

                我发现在尝试通过公司代理安装时出现 node-sass 错误。第一个解决方案是确保您的 .npmrc 文件具有代理权限。

                .npmrc

                # Try removing reference to registry, as sometimes your local corporate registry of node_modules may not include node-sass
                # // registry=https://....
                
                # note if using special characters in pass, encode them: eg: h@ppy = h%40ppy
                strict-ssl=false
                proxy=http://<username>:<pass>@proxyhost:<port>
                https-proxy=http://<uname>:<pass>@proxyhost:<port>
                

                NODE_TLS_REJECT_UNAUTHORIZED = 0

                然后在运行任何安装之前在命令行中

                set NODE_TLS_REJECT_UNAUTHORIZED = 0
                

                从 node-sass github 站点压缩节点绑定文件,以便通过公司网络下载它们。

                示例: https://github.com/inspiraller/node-sass-bindings

                【讨论】:

                  【解决方案8】:

                  您需要执行后续步骤,它应该可以工作:

                  rm -rf node_modules package-lock.json 
                  npm install --saveDev node-sass@4.5.3 
                  npm install
                  

                  瞧 :)

                  【讨论】:

                  • 具体4.5.3版本有什么意义?如何为我的环境确定此版本?我的 package.json 正在尝试安装 ^4.11.0 node-sass
                  【解决方案9】:

                  支持 Node 8 的最低版本是 4.5.3。顺便说一句,我认为 2.x 不会支持 Node 0.12 以上的任何东西,即 EOL。

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 2021-07-28
                    • 1970-01-01
                    • 2017-04-25
                    • 2021-11-17
                    • 2021-02-18
                    • 1970-01-01
                    • 1970-01-01
                    • 2021-12-18
                    相关资源
                    最近更新 更多