问题:使用本地二进制安装 node-sass 时出错

我在公司代理后面使用节点 14 和 Jenkins,我无法正确安装 node-sass。

所以我在两个地方本地安装了它

  • 对于 SASS\BINARY\PATH:/var/jenkins_home/linux-x64-83_binding.node

  • 对于 SASS_BINARY_DIR:/var/jenkins_home/vendor/linux-x64-83/binding.node

我试过SASS_BINARY_PATH:

SASS_BINARY_PATH=/var/jenkins_home/linux-x64-83_binding.node npm install node-sass
npm install --no-lockfile
npm run build

但是在构建时出现此错误:

模块构建失败(来自 ./node_modules/mini-css-extract-plugin/dist/loader.js):ModuleBuildError: 模块构建失败(来自 ./node_modules/sass-loader/dist/cjs.js) :错误:ENOENT:没有这样的文件或目录,scandir '/var/jenkins_home/workspace/root_project_dir/project/node_modules/node-sass/vendor'

我试过SASS_BINARY_DIR:

SASS_BINARY_DIR=/var/jenkins_home/vendor npm install node-sass
npm install --no-lockfile
npm run build

但这最终会尝试下载二进制文件,这是我首先要避免的问题。

任何帮助将不胜感激!

如果有帮助,这是我的 package.json:

{
  "name": "name",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "@types/lodash": "4.14.115",
    "axios": "^0.18.0",
    "@types/chart.js": "^2.7.48",
    "chart.js": "^2.7.2",
    "chartjs-plugin-datalabels": "0.7.0",
    "http2": "^3.3.7",
    "lodash": "4.17.10",
    "typescript": "^3.2.0",
    "vue": "^2.5.16",
    "vue-async-computed": "^3.3.1",
    "vue-chartjs": "^3.4.0",
    "vue-class-component": "^6.0.0",
    "vue-property-decorator": "^7.0.0",
    "vue-router": "^3.0.1"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.0.0-rc.12",
    "@vue/cli-plugin-typescript": "^3.0.0-beta.15",
    "@vue/cli-service": "^3.0.0-beta.15",
    "node-sass": "^4.9.0",
    "sass-loader": "^7.0.1",
    "vue-template-compiler": "^2.5.16"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

解答

我通过在npm install之后手动创建node_modules/node-sass/vendor目录并将binding.node复制到linux-x64-83目录中解决了这个问题:

npm install node-sass --sass-binary-path="/var/jenkins_home/linux-x64-83_binding.node"
npm install --no-lockfile
mkdir -p node_modules/node-sass/vendor/linux-x64-83
cp /var/jenkins_home/linux-x64-83_binding.node node_modules/node-sass/vendor/linux-x64-83/binding.node
npm run build
Logo

CI/CD社区为您提供最前沿的新闻资讯和知识内容

更多推荐