• node-sass安装失败 error D:xxxxxx ode_modules ode-sass: Command failed.(window + mac M1 pro)


    error D:xxxxxx ode_modules ode-sass: Command failed.

    导言:运行老项目的时候经常遇到node-sass安装不下来的问题,百度搜索更是千篇一律的镜像原因,当然镜像问题原因是更多人可能遇到的问题,比较少见的一种是运行老项目时,node版本比较低,导致node-sass安装不了

    提示node-sass安装异常我遇到过两种情况,一种是安装依赖时需要node-sass,报错一般是↓↓↓

    error D:xxxxxx
    ode_modules
    ode-sass: Command failed.
    Exit code: 1
    Command: node scripts/build.js
    Arguments:
    Directory: D:xxxxxx
    ode_modules
    ode-sass
    Output:
    Binary found at D:software
    odesasswin32-x64-72_binding.node
    Testing binary
    Binary has a problem: Error: The module '\?D:software
    odesasswin32-x64-72_binding.node'
    was compiled against a different Node.js version using
    NODE_MODULE_VERSION 72. This version of Node.js requires
    NODE_MODULE_VERSION 64. Please try re-compiling or re-installing
    the module (for instance, using `npm rebuild` or `npm install`).
        at Object.Module._extensions..node (internal/modules/cjs/loader.js:717:18)
        at Module.load (internal/modules/cjs/loader.js:598:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
        at Function.Module._load (internal/modules/cjs/loader.js:529:3)
        at Module.require (internal/modules/cjs/loader.js:636:17)
        at require (internal/modules/cjs/helpers.js:20:18)
        at module.exports (D:xxxxxx
    ode_modules
    ode-sasslibinding.js:19:10)
        at Object.<anonymous> (D:xxxxxx
    ode_modules
    ode-sasslibindex.js:14:35)
        at Module._compile (internal/modules/cjs/loader.js:688:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    Building the binary locally
    Building: C:Program Files
    odejs
    ode.exe D:xxxxxx
    ode_modules
    ode-gypin
    ode-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
    gyp info it worked if it ends with ok
    gyp verb cli [ 'C:\Program Files\nodejs\node.exe',
    gyp verb cli   'D:\xxx\xxx\node_modules\node-gyp\bin\node-gyp.js',
    gyp verb cli   'rebuild',
    gyp verb cli   '--verbose',
    gyp verb cli   '--libsass_ext=',
    gyp verb cli   '--libsass_cflags=',
    gyp verb cli   '--libsass_ldflags=',
    gyp verb cli   '--libsass_library=' ]
    gyp info using node-gyp@3.8.0
    gyp info using node@10.14.1 | win32 | x64
    gyp verb command rebuild []
    gyp verb command clean []
    gyp verb clean removing "build" directory
    gyp verb command configure []
    gyp verb check python checking for Python executable "python2" in the PATH
    gyp verb `which` failed Error: not found: python2
    gyp verb `which` failed     at getNotFoundError (D:xxxxxx
    ode_moduleswhichwhich.js:13:12)
    gyp verb `which` failed     at F (D:xxxxxx
    ode_moduleswhichwhich.js:68:19)
    gyp verb `which` failed     at E (D:xxxxxx
    ode_moduleswhichwhich.js:80:29)
    gyp verb `which` failed     at D:xxxxxx
    ode_moduleswhichwhich.js:89:16
    gyp verb `which` failed     at D:xxxxxx
    ode_modulesisexeindex.js:42:5
    gyp verb `which` failed     at D:xxxxxx
    ode_modulesisexewindows.js:36:5
    gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
    gyp verb `which` failed  python2 { Error: not found: python2
    gyp verb `which` failed     at getNotFoundError (D:xxxxxx
    ode_moduleswhichwhich.js:13:12)
    gyp verb `which` failed     at F (D:xxxxxx
    ode_moduleswhichwhich.js:68:19)
    gyp verb `which` failed     at E (D:xxxxxx
    ode_moduleswhichwhich.js:80:29)
    gyp verb `which` failed     at D:xxxxxx
    ode_moduleswhichwhich.js:89:16
    gyp verb `which` failed     at D:xxxxxx
    ode_modulesisexeindex.js:42:5
    gyp verb `which` failed     at D:xxxxxx
    ode_modulesisexewindows.js:36:5
    gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
    gyp verb `which` failed   stack:
    gyp verb `which` failed    'Error: not found: python2
        at getNotFoundError (D:\xxx\xxx\node_modules\which\which.js:13:12)
        at F (D:\xxx\xxx\node_modules\which\which.js:68:19)
        at E (D:\xxx\xxx\node_modules\which\which.js:80:29)
        at D:\xxx\xxx\node_modules\which\which.js:89:16
        at D:\xxx\xxx\node_modules\isexe\index.js:42:5
        at D:\xxx\xxx\node_modules\isexe\windows.js:36:5
        at FSReqWrap.oncomplete (fs.js:154:21)',
    gyp verb `which` failed   code: 'ENOENT' }
    gyp verb check python checking for Python executable "python" in the PATH
    gyp verb `which` failed Error: not found: python
    gyp verb `which` failed     at getNotFoundError (D:xxxxxx
    ode_moduleswhichwhich.js:13:12)
    gyp verb `which` failed     at F (D:xxxxxx
    ode_moduleswhichwhich.js:68:19)
    gyp verb `which` failed     at E (D:xxxxxx
    ode_moduleswhichwhich.js:80:29)
    gyp verb `which` failed     at D:xxxxxx
    ode_moduleswhichwhich.js:89:16
    gyp verb `which` failed     at D:xxxxxx
    ode_modulesisexeindex.js:42:5
    gyp verb `which` failed     at D:xxxxxx
    ode_modulesisexewindows.js:36:5
    gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
    gyp verb `which` failed  python { Error: not found: python
    gyp verb `which` failed     at getNotFoundError (D:xxxxxx
    ode_moduleswhichwhich.js:13:12)
    gyp verb `which` failed     at F (D:xxxxxx
    ode_moduleswhichwhich.js:68:19)
    gyp verb `which` failed     at E (D:xxxxxx
    ode_moduleswhichwhich.js:80:29)
    gyp verb `which` failed     at D:xxxxxx
    ode_moduleswhichwhich.js:89:16
    gyp verb `which` failed     at D:xxxxxx
    ode_modulesisexeindex.js:42:5
    gyp verb `which` failed     at D:xxxxxx
    ode_modulesisexewindows.js:36:5
    gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:154:21)
    gyp verb `which` failed   stack:
    gyp verb `which` failed    'Error: not found: python
        at getNotFoundError (D:\xxx\xxx\node_modules\which\which.js:13:12)
        at F (D:\xxx\xxx\node_modules\which\which.js:68:19)
        at E (D:\xxx\xxx\node_modules\which\which.js:80:29)
        at D:\xxx\xxx\node_modules\which\which.js:89:16
        at D:\xxx\xxx\node_modules\isexe\index.js:42:5
        at D:\xxx\xxx\node_modules\isexe\windows.js:36:5
        at FSReqWrap.oncomplete (fs.js:154:21)',
    gyp verb `which` failed   code: 'ENOENT' }
    gyp verb could not find "python". checking python launcher
    gyp verb could not find "python". guessing location
    gyp verb ensuring that file exists: C:Python27python.exe
    gyp ERR! configure error
    gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
    gyp ERR! stack     at PythonFinder.failNoPython (D:xxxxxx
    ode_modules
    ode-gyplibconfigure.js:484:19)
    gyp ERR! stack     at PythonFinder.<anonymous> (D:xxxxxx
    ode_modules
    ode-gyplibconfigure.js:509:16)
    gyp ERR! stack     at D:xxxxxx
    ode_modulesgraceful-fspolyfills.js:284:29
    gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:154:21)
    gyp ERR! System Windows_NT 10.0.19042
    gyp ERR! command "C:\Program Files\nodejs\node.exe" "D:\xxx\xxx\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
    gyp ERR! cwd D:xxxxxx
    ode_modules
    ode-sass
    gyp ERR! node -v v10.14.1
    gyp ERR! node-gyp -v v3.8.0
    gyp ERR! not ok
    Build failed with error code: 1
    info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
    

    一种是依赖安装成功,但跑项目时因为部分依赖依赖了node-sass导致运行不成功,异常一般是↓↓↓

    internal/modules/cjs/loader.js:717
      return process.dlopen(module, path.toNamespacedPath(filename));
                     ^
    
    Error: The module '\?D:
    odesasswin32-x64-72_binding.node'
    was compiled against a different Node.js version using
    NODE_MODULE_VERSION 72. This version of Node.js requires
    NODE_MODULE_VERSION 64. Please try re-compiling or re-installing
    the module (for instance, using `npm rebuild` or `npm install`).
        at Object.Module._extensions..node (internal/modules/cjs/loader.js:717:18)
        at Module.load (internal/modules/cjs/loader.js:598:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
        at Function.Module._load (internal/modules/cjs/loader.js:529:3)
        at Module.require (internal/modules/cjs/loader.js:636:17)
        at require (internal/modules/cjs/helpers.js:20:18)
        at module.exports (D:xxxxxx
    ode_modules
    ode-sasslibinding.js:19:10)
        at Object.<anonymous> (D:xxxxxx
    ode_modules
    ode-sasslibindex.js:14:35)
        at Module._compile (internal/modules/cjs/loader.js:688:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    

    出现这种情况一般都是node-sass版本和node版本不对应,拿以上错误举例

    This version of Node.js requires NODE_MODULE_VERSION 64.
    

    这句话的意思是:此版本的Node.js需要使用64版本的node-sass

    可以去GitHub找到node-sass的对应版本:

    https://github.com/sass/node-sass/releases

    比如说我当前使用的node版本是10.14.1,则找到对应系统的对应node版本

    image

    下载对应系统对应node版本所需的node-sass

    image

    下载后放到本地磁盘,比如D盘


    如果是安装依赖时出了错,则建议先把之前安装的node_modules删掉,然后设置node-sass路径↓↓↓

    // 删除node_modules建议用命令行,更快!!
    rmdir /s node_modules
    
    // set SASS_BINARY_PATH=node-sass所在的路径
    set SASS_BINARY_PATH=D:/nodesass/win32-x64-64_binding.node
    

    设置好node-sass路径好正常安装依赖即可

    npm i 或 yarn
    

    如果安装依赖成功,但运行时出了node-sass的错,则直接设置node-sass路径然后运行↓↓↓

    // set SASS_BINARY_PATH=node-sass所在的路径
    set SASS_BINARY_PATH=D:/nodesass/win32-x64-64_binding.node
    
    npm run dev 或 yarn dev
    

    注意:如果你通过以上方法成功安装了依赖并成功运行了,但是,你在同时维护几个不同node版本的项目,需要切换不同版本的node-sass和node,则建议切换项目后再设置一下node-sass路径。


    【补充】mac M1 pro node-sass 安装失败解决方法
    说明:经过尝试,发现 node-sass 好像不兼容 m1 ,所以建议将 node-sass 替换为 sass

    1. 删除package.json 中的 node-sass 和 sass-loader
    2. 删除 yarn.log !!!!!! (特别重要)
    3. 删除 node_modules,终端指令 rm -rf node_modules
    4. node 版本切换为 14+
    5. 安装 sass, yarn add -D sass 或 npm install --save-dev sass
    6. 安装依赖 yarn

    end~

  • 相关阅读:
    回顾2018,展望2019
    NLog日志框架使用探究-1
    基于NetMQ的TLS框架NetMQ.Security的实现分析
    鸟哥的Linux私房菜笔记第五章,文件权限与目录配置(二)
    鸟哥的Linux私房菜笔记第五章,文件权限与目录配置(一)
    鸟哥的Linux私房菜笔记第四章
    ThinkPHP5.1 + tufanbarisyildirim 解析apk
    Java核心技术第八章——泛型程序设计(1)
    Java核心技术第五章——2.Object类
    Java核心技术第五章——1.类、超类、子类(2)
  • 原文地址:https://www.cnblogs.com/huasonglin/p/14777752.html
Copyright © 2020-2023  润新知