美文网首页
解决node-sass binding.node问题

解决node-sass binding.node问题

作者: 爱写作的harry | 来源:发表于2020-05-10 14:56 被阅读0次

    使用node-sass遇到了错误,google了一圈没发现几个有帮助的,参考了一个答案,最终解决了这个问题。在这里做个笔记,给碰到同样问题的人。

    2020-06-14 更新:最终发现是mac下python的问题,重新安装一下就好了:

    brew reinstall python@2
    

    错误的log:

    ERROR in ./src/ui/styles/global.scss (./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/ui/styles/global.scss)
    Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
    Error: Missing binding YOUR_PROJECT_PATH/node_modules/node-sass/vendor/darwin-x64-72/binding.node
    Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 12.x
    
    Found bindings for the following environments:
      - OS X 64-bit with Node.js 12.x
    
    This usually happens because your environment has changed since running `npm install`.
    Run `npm rebuild node-sass` to download the binding for your current environment.
        at module.exports (YOUR_PROJECT_PATH/node_modules/node-sass/lib/binding.js:15:13)
        at Object.<anonymous> (YOUR_PROJECT_PATH/node_modules/node-sass/lib/index.js:14:35)
        at Module._compile (YOUR_PROJECT_PATH/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
        at Module.load (internal/modules/cjs/loader.js:628:32)
        at Function.Module._load (internal/modules/cjs/loader.js:555:12)
        at Module.require (internal/modules/cjs/loader.js:666:19)
        at require (YOUR_PROJECT_PATH/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
        at getDefaultSassImplementation (YOUR_PROJECT_PATH/node_modules/sass-loader/dist/getDefaultSassImplementation.js:24:10)
        at getSassImplementation (YOUR_PROJECT_PATH/node_modules/sass-loader/dist/getSassImplementation.js:19:72)
        at Object.loader (YOUR_PROJECT_PATH/node_modules/sass-loader/dist/index.js:40:61)
     @ ./src/ui/styles/global.scss 2:26-143
     @ ./src/ui/App.tsx
     @ ./src/ui/index.tsx
    

    注意错误log中的路径是:node_modules/node-sass/vendor/darwin-x64-72/binding.node

    npm rebuild node-sass会去下载对应的binding.node。如果用npm rebuild node-sass 下载失败,可以尝试手动下载对应的binding.node。具体步骤:

    解决方法:
    1. 访问url https://github.com/sass/node-sass/releases
    2. 找到对应的 darwin-x64-72 名字,我的是 darwin-x64-72_binding.node,下载到本地的 node_modules/node-sass/vendor/darwin-x64-72/ 目录中
    3. 将 darwin-x64-72_binding.node 改为 binding.node
    4. done

    参考:https://stackoverflow.com/a/41304976/3086481

    相关文章

      网友评论

          本文标题:解决node-sass binding.node问题

          本文链接:https://www.haomeiwen.com/subject/dzjjnhtx.html