nuxt项目ci部署 node-sass问题

Posted auserroot

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nuxt项目ci部署 node-sass问题相关的知识,希望对你有一定的参考价值。

node-sass 安装失败导致ci部署失败

> node-sass@5.0.0 postinstall /node_modules/node-sass
> node scripts/build.js
Building: /usr/local/bin/node /node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   '/usr/local/bin/node',
gyp verb cli   '/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 verb cli ]
gyp info using node-gyp@7.1.2
gyp info using node@12.20.1 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb find Python Python is not set from command line or npm configuration
gyp verb find Python Python is not set from environment variable PYTHON
gyp verb find Python checking if "python3" can be used
gyp verb find Python - executing "python3" to get executable path
gyp verb find Python - "python3" is not in PATH or produced an error
gyp verb find Python checking if "python" can be used
gyp verb find Python - executing "python" to get executable path
gyp verb find Python - "python" is not in PATH or produced an error
gyp verb find Python checking if "python2" can be used
gyp verb find Python - executing "python2" to get executable path
gyp verb find Python - "python2" is not in PATH or produced an error
gyp ERR! find Python 
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python3" can be used
gyp ERR! find Python - "python3" is not in PATH or produced an error
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - "python" is not in PATH or produced an error
gyp ERR! find Python checking if "python2" can be used
gyp ERR! find Python - "python2" is not in PATH or produced an error
gyp ERR! find Python 
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python 
gyp ERR! configure error 
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (/node_modules/node-gyp/lib/find-python.js:302:47)
gyp ERR! stack     at PythonFinder.runChecks (/node_modules/node-gyp/lib/find-python.js:136:21)
gyp ERR! stack     at PythonFinder.<anonymous> (/node_modules/node-gyp/lib/find-python.js:179:16)
gyp ERR! stack     at PythonFinder.execFileCallback (/node_modules/node-gyp/lib/find-python.js:266:16)
gyp ERR! stack     at exithandler (child_process.js:315:5)
gyp ERR! stack     at ChildProcess.errorhandler (child_process.js:327:5)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
gyp ERR! stack     at onErrorNT (internal/child_process.js:470:16)
gyp ERR! stack     at processTicksAndRejections (internal/process/task_queues.js:84:21)
gyp ERR! System Linux 3.10.0-123.9.3.el7.x86_64
gyp ERR! command "/usr/local/bin/node" "/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /node_modules/node-sass
gyp ERR! node -v v12.20.1
gyp ERR! node-gyp -v v7.1.2
gyp ERR! not ok 
Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted "os":"darwin","arch":"any" (current: "os":"linux","arch":"x64")
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack-chokidar2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted "os":"darwin","arch":"any" (current: "os":"linux","arch":"x64")
npm WARN notsup Unsupported engine for @nuxtjs/style-resources@1.2.1: wanted: "node":">=v10.24.1","npm":">=6.14.14" (current: "node":"12.20.1","npm":"6.14.10")
npm WARN notsup Not compatible with your version of node/npm: @nuxtjs/style-resources@1.2.1
npm WARN notsup Unsupported engine for eslint-plugin-vue@8.2.0: wanted: "node":"^12.22.0 || ^14.17.0 || >=16.0.0" (current: "node":"12.20.1","npm":"6.14.10")
npm WARN notsup Not compatible with your version of node/npm: eslint-plugin-vue@8.2.0
npm WARN notsup Unsupported engine for vue-eslint-parser@8.0.1: wanted: "node":"^12.22.0 || ^14.17.0 || >=16.0.0" (current: "node":"12.20.1","npm":"6.14.10")
npm WARN notsup Not compatible with your version of node/npm: vue-eslint-parser@8.0.1
npm WARN notsup Unsupported engine for eslint-scope@6.0.0: wanted: "node":"^12.22.0 || ^14.17.0 || >=16.0.0" (current: "node":"12.20.1","npm":"6.14.10")
npm WARN notsup Not compatible with your version of node/npm: eslint-scope@6.0.0
npm WARN notsup Unsupported engine for eslint-visitor-keys@3.1.0: wanted: "node":"^12.22.0 || ^14.17.0 || >=16.0.0" (current: "node":"12.20.1","npm":"6.14.10")
npm WARN notsup Not compatible with your version of node/npm: eslint-visitor-keys@3.1.0
npm WARN notsup Unsupported engine for espree@9.2.0: wanted: "node":"^12.22.0 || ^14.17.0 || >=16.0.0" (current: "node":"12.20.1","npm":"6.14.10")
npm WARN notsup Not compatible with your version of node/npm: espree@9.2.0
npm WARN notsup Unsupported engine for eslint-visitor-keys@3.1.0: wanted: "node":"^12.22.0 || ^14.17.0 || >=16.0.0" (current: "node":"12.20.1","npm":"6.14.10")
npm WARN notsup Not compatible with your version of node/npm: eslint-visitor-keys@3.1.0
npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@5.0.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-sass@5.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:

解决

一:

上传:package-lock.json 限定node-sass 版本 和 包源

"node-sass": 
      "version": "5.0.0",
      "resolved": "https://registry.npm.taobao.org/node-sass/download/node-sass-5.0.0.tgz?cache=0&sync_timestamp=1604150653238&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnode-sass%2Fdownload%2Fnode-sass-5.0.0.tgz",
      "integrity": "sha1-To85++87rI0txy6+O1OXEYg6eNI=",
      "dev": true,
      "requires": 
        "async-foreach": "^0.1.3",
        "chalk": "^1.1.1",
        "cross-spawn": "^7.0.3",
        "gaze": "^1.0.0",
        "get-stdin": "^4.0.1",
        "glob": "^7.0.3",
        "lodash": "^4.17.15",
        "meow": "^3.7.0",
        "mkdirp": "^0.5.1",
        "nan": "^2.13.2",
        "node-gyp": "^7.1.0",
        "npmlog": "^4.0.0",
        "request": "^2.88.0",
        "sass-graph": "2.2.5",
        "stdout-stream": "^1.4.0",
        "true-case-path": "^1.0.2"
      ,
      "dependencies": 
        "ansi-regex": 
          "version": "2.1.1",
          "resolved": "https://registry.npm.taobao.org/ansi-regex/download/ansi-regex-2.1.1.tgz",
          "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
          "dev": true
        ,
        "ansi-styles": 
          "version": "2.2.1",
          "resolved": "https://registry.npm.taobao.org/ansi-styles/download/ansi-styles-2.2.1.tgz?cache=0&sync_timestamp=1611325747047&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fansi-styles%2Fdownload%2Fansi-styles-2.2.1.tgz",
          "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=",
          "dev": true
        ,
        "chalk": 
          "version": "1.1.3",
          "resolved": "https://registry.npm.taobao.org/chalk/download/chalk-1.1.3.tgz",
          "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
          "dev": true,
          "requires": 
            "ansi-styles": "^2.2.1",
            "escape-string-regexp": "^1.0.2",
            "has-ansi": "^2.0.0",
            "strip-ansi": "^3.0.0",
            "supports-color": "^2.0.0"
          
        ,
        "cross-spawn": 
          "version": "7.0.3",
          "resolved": "https://registry.npm.taobao.org/cross-spawn/download/cross-spawn-7.0.3.tgz",
          "integrity": "sha1-9zqFudXUHQRVUcF34ogtSshXKKY=",
          "dev": true,
          "requires": 
            "path-key": "^3.1.0",
            "shebang-command": "^2.0.0",
            "which": "^2.0.1"
          
        ,
        "strip-ansi": 
          "version": "3.0.1",
          "resolved": "https://registry.npm.taobao.org/strip-ansi/download/strip-ansi-3.0.1.tgz?cache=0&sync_timestamp=1589682795383&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fstrip-ansi%2Fdownload%2Fstrip-ansi-3.0.1.tgz",
          "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
          "dev": true,
          "requires": 
            "ansi-regex": "^2.0.0"
          
        ,
        "supports-color": 
          "version": "2.0.0",
          "resolved": "https://registry.npm.taobao.org/supports-color/download/supports-color-2.0.0.tgz?cache=0&sync_timestamp=1611394878204&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsupports-color%2Fdownload%2Fsupports-color-2.0.0.tgz",
          "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
          "dev": true
        
      
    ,

二:

修改ci中命令手动修改node-sass 包源

npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
  • 修复 gyp 问题:
运行以下命令
npm install -g node-gyp 

npm install –global –production windows-build-tools

三:

使用dart-sass替换node-sass

npm install node-sass@npm:dart-sass

以上是关于nuxt项目ci部署 node-sass问题的主要内容,如果未能解决你的问题,请参考以下文章

我应该将我的 Nuxt 应用程序直接部署到 Google App Engine 还是应该在我的代码存在于存储库中的地方使用 Gitlab CI/CD?

有没有办法在 Nuxt.js 中使用 sass 而不是 node-sass(默认为 sass-loader)?

如何在Nuxt项目中使用.vue文件做自动前缀处理?

CentOS 6.8部署Nuxt.js项目(CentOS nuxt.js项目无法通过公网IP访问的问题)

在 Nuxt 中使用最新的 SASS 和 @use

如何将nuxt项目部署到github pages (码云 pages) 上