解决自动化部署npm安装sass报错,往往是node版本太高导致的问题

 更新时间:2026年03月11日 16:33:18   作者:1024小神  
在使用GitHub Actions自动化部署npm安装sass时遇到报错,原因是Node.js版本过高,本地开发使用14.18.3版本,而GitHub Actions默认使用最新版本,导致兼容性问题,解决方法是指定与本地版本相近的Node.js版本,或者指定多个版本供GitHub Actions选择

自动化部署npm安装sass报错

本想尝试一下github的自动化部署,将一个vue项目部署到github pages上面,结果报错:

报错

npm ERR! code 1

50npm ERR! path /home/runner/work/CvReport/CvReport/node_modules/node-sass

51npm ERR! command failed

52npm ERR! command sh -c -- node scripts/build.js

53npm ERR! Building: /usr/local/bin/node /home/runner/work/CvReport/CvReport/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=

54npm ERR! gyp info it worked if it ends with ok

55npm ERR! gyp verb cli [

56npm ERR! gyp verb cli '/usr/local/bin/node',

57npm ERR! gyp verb cli '/home/runner/work/CvReport/CvReport/node_modules/node-gyp/bin/node-gyp.js',

58npm ERR! gyp verb cli 'rebuild',

59npm ERR! gyp verb cli '--verbose',

60npm ERR! gyp verb cli '--libsass_ext=',

61npm ERR! gyp verb cli '--libsass_cflags=',

62npm ERR! gyp verb cli '--libsass_ldflags=',

63npm ERR! gyp verb cli '--libsass_library='

64npm ERR! gyp verb cli ]

65npm ERR! gyp info using node-gyp@3.8.0

66npm ERR! gyp info using node@16.18.1 | linux | x64

67npm ERR! gyp verb command rebuild []

68npm ERR! gyp verb command clean []

69npm ERR! gyp verb clean removing "build" directory

70npm ERR! gyp verb command configure []

71npm ERR! gyp verb check python checking for Python executable "python2" in the PATH

72npm ERR! gyp verb `which` failed Error: not found: python2

73npm ERR! gyp verb `which` failed at getNotFoundError (/home/runner/work/CvReport/CvReport/node_modules/which/which.js:13:12)

74npm ERR! gyp verb `which` failed at F (/home/runner/work/CvReport/CvReport/node_modules/which/which.js:68:19)

75npm ERR! gyp verb `which` failed at E (/home/runner/work/CvReport/CvReport/node_modules/which/which.js:80:29)

76npm ERR! gyp verb `which` failed at /home/runner/work/CvReport/CvReport/node_modules/which/which.js:89:16

77npm ERR! gyp verb `which` failed at /home/runner/work/CvReport/CvReport/node_modules/isexe/index.js:42:5

78npm ERR! gyp verb `which` failed at /home/runner/work/CvReport/CvReport/node_modules/isexe/mode.js:8:5

79npm ERR! gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:202:21)

80npm ERR! gyp verb `which` failed python2 Error: not found: python2

81npm ERR! gyp verb `which` failed at getNotFoundError (/home/runner/work/CvReport/CvReport/node_modules/which/which.js:13:12)

82npm ERR! gyp verb `which` failed at F (/home/runner/work/CvReport/CvReport/node_modules/which/which.js:68:19)

83npm ERR! gyp verb `which` failed at E (/home/runner/work/CvReport/CvReport/node_modules/which/which.js:80:29)

84npm ERR! gyp verb `which` failed at /home/runner/work/CvReport/CvReport/node_modules/which/which.js:89:16

85npm ERR! gyp verb `which` failed at /home/runner/work/CvReport/CvReport/node_modules/isexe/index.js:42:5

86npm ERR! gyp verb `which` failed at /home/runner/work/CvReport/CvReport/node_modules/isexe/mode.js:8:5

87npm ERR! gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:202:21) {

88npm ERR! gyp verb `which` failed code: 'ENOENT'

89npm ERR! gyp verb `which` failed }

90npm ERR! gyp verb check python checking for Python executable "python" in the PATH

91npm ERR! gyp verb `which` succeeded python /usr/bin/python

92npm ERR! gyp ERR! configure error

93npm ERR! gyp ERR! stack Error: Command failed: /usr/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];

94npm ERR! gyp ERR! stack File "<string>", line 1

95npm ERR! gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];

96npm ERR! gyp ERR! stack ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

97npm ERR! gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

98npm ERR! gyp ERR! stack

99npm ERR! gyp ERR! stack at ChildProcess.exithandler (node:child_process:402:12)

100npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28)

101npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1100:16)

102npm ERR! gyp ERR! stack at Socket.<anonymous> (node:internal/child_process:458:11)

103npm ERR! gyp ERR! stack at Socket.emit (node:events:513:28)

104npm ERR! gyp ERR! stack at Pipe.<anonymous> (node:net:301:12)

105npm ERR! gyp ERR! System Linux 5.15.0-1024-azure

106npm ERR! gyp ERR! command "/usr/local/bin/node" "/home/runner/work/CvReport/CvReport/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="

107npm ERR! gyp ERR! cwd /home/runner/work/CvReport/CvReport/node_modules/node-sass

108npm ERR! gyp ERR! node -v v16.18.1

109npm ERR! gyp ERR! node-gyp -v v3.8.0

110npm ERR! gyp ERR! not ok

111npm ERR! Build failed with error code: 1

112

113npm ERR! A complete log of this run can be found in:

114npm ERR! /home/runner/.npm/_logs/2022-12-13T06_06_26_664Z-debug-0.log

115Error: Process completed with exit code 1.

原因

node版本太高导致的,我本地开发用的是14.18.3,但是使用github action部署的时候,如果不指定默认的,就会用最新版的,所以就导致了不成功,需要指定和本地版本差不多的版本,或者指定多个版本:

name: Node.js CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x, 12.x, 14.x, 15.x]

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - run: npm run build --if-present
      - run: npm test

您也可以使用单个版本的 Node.js 构建和测试:

name: Node.js CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '12.x'
      - run: npm ci
      - run: npm run build --if-present
      - run: npm test

就会成功了:看吧,14成功了,15就失败

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • node.js中的querystring.unescape方法使用说明

    node.js中的querystring.unescape方法使用说明

    这篇文章主要介绍了node.js中的querystring.unescape方法使用说明,本文介绍了querystring.unescape的方法说明、语法、接收参数、使用实例和实现源码,需要的朋友可以参考下
    2014-12-12
  • puppeteer库入门初探

    puppeteer库入门初探

    这篇文章主要介绍了puppeteer库入门初探,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-01-01
  • node.js中的path.basename方法使用说明

    node.js中的path.basename方法使用说明

    这篇文章主要介绍了node.js中的path.basename方法使用说明,本文介绍了path.basename的方法说明、语法、使用实例和实现源码,需要的朋友可以参考下
    2014-12-12
  • nodejs做个爬虫爬取腾讯动漫内容简单实现

    nodejs做个爬虫爬取腾讯动漫内容简单实现

    这篇文章主要为大家介绍了nodejs做个爬虫爬取腾讯动漫内容简单实现,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-07-07
  • Node.js原理阻塞和EventEmitter及其继承的运用实战

    Node.js原理阻塞和EventEmitter及其继承的运用实战

    这篇文章主要介绍了Node.js原理阻塞和EventEmitter及其继承的运用实战,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下
    2022-08-08
  • Node.js16.15.1的一个报错以及解决方案分享

    Node.js16.15.1的一个报错以及解决方案分享

    这篇文章主要给大家介绍了关于Node.js16.15.1的一个报错以及解决方案的相关资料,文中通过图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2022-12-12
  • 提高Node.js性能的应用技巧分享

    提高Node.js性能的应用技巧分享

    Node.js 是单线程非阻塞 I/O, 使其可以支持成千上万的并发操作。这和 NGINX 解决 C10K 问题的方式如出一辙。Node.js 以高效的性能和开发效率著称。
    2017-08-08
  • 深入理解Node.js中import.meta的使用

    深入理解Node.js中import.meta的使用

    import.meta提供模块的上下文信息,如文件URL、解析模块路径、判断模块是否为入口等,本文就来介绍一下Node.js中import.meta的使用,具有一定的参考价值,感兴趣的可以了解一下
    2026-01-01
  • node.js中的fs.fchown方法使用说明

    node.js中的fs.fchown方法使用说明

    这篇文章主要介绍了node.js中的fs.fchown方法使用说明,本文介绍了fs.fchown方法说明、语法、接收参数、使用实例和实现源码,需要的朋友可以参考下
    2014-12-12
  • pnpm的安装及其使用教程(汇总)

    pnpm的安装及其使用教程(汇总)

    pnpm是 Node.js 的替代包管理器,它是 npm 的直接替代品,速度更快、效率更高,它由 npm/yarn 衍生而来,但却解决了 npm/yarn 内部潜在的 bug,并且极大了地优化了性能,本文给大家介绍pnpm的安装及其使用,感兴趣的朋友一起看看吧
    2023-12-12

最新评论