使用本地二进制文件安装 node-sass 时出错
Error installing node-sass using local binary
我在公司代理后面使用 node 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
但是我在构建时遇到这个错误:
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
Error: ENOENT: no such file or directory, 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
假设您有一个空目录 C:\res\node-sass
,它将用作 SASS_BINARY_DIR
。以下步骤显示了我如何正确指定 SASS_BINARY_DIR
:
- 使用
npm install
在项目根目录下安装包
在控制台打印的内容中,找到一个类似于https://github.com/sass/node-sass/releases/download/v4.14.1/win32-x64-83_binding.node 的link
- 手动下载https://github.com/sass/node-sass/releases/download/v4.14.1/win32-x64-83_binding.node,并保存为
win32-x64-83_binding.node
- 在C:\res\node-sass下创建一个名为
win32-x64-83
的子目录,注意win32-x64-83
来自部分文件名win32-x64-83_binding.node
- 将下载的win32-x64-83_binding.node复制到文件夹C:\res\node-sass\win32-x64-83中,并将文件重命名为
binding.node
- 将
SASS_BINARY_DIR=C:\res\node-sass
添加到应用程序根目录下的.npmrc
- 继续下载
npm i
这次,npm 将去 SASS_BINARY_DIR 查找二进制源,而不是从 github. 下载它
所以下载的win32-x64-83_binding.node
实际上变成了%SASS_BINARY_DIR%\win32-x64-83\binding.node
除了在文件 .npmrc
中指定 SASS_BINARY_DIR 外,您还可以在 windows.
上使用 set SASS_BINARY_DIR=C:\res\node-sass
将其导出为环境变量
我在公司代理后面使用 node 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
但是我在构建时遇到这个错误:
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js): Error: ENOENT: no such file or directory, 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
假设您有一个空目录 C:\res\node-sass
,它将用作 SASS_BINARY_DIR
。以下步骤显示了我如何正确指定 SASS_BINARY_DIR
:
- 使用
npm install
在项目根目录下安装包
在控制台打印的内容中,找到一个类似于https://github.com/sass/node-sass/releases/download/v4.14.1/win32-x64-83_binding.node 的link
- 手动下载https://github.com/sass/node-sass/releases/download/v4.14.1/win32-x64-83_binding.node,并保存为
win32-x64-83_binding.node
- 在C:\res\node-sass下创建一个名为
win32-x64-83
的子目录,注意win32-x64-83
来自部分文件名win32-x64-83_binding.node
- 将下载的win32-x64-83_binding.node复制到文件夹C:\res\node-sass\win32-x64-83中,并将文件重命名为
binding.node
- 将
SASS_BINARY_DIR=C:\res\node-sass
添加到应用程序根目录下的.npmrc - 继续下载
npm i
这次,npm 将去 SASS_BINARY_DIR 查找二进制源,而不是从 github. 下载它
所以下载的win32-x64-83_binding.node
实际上变成了%SASS_BINARY_DIR%\win32-x64-83\binding.node
除了在文件 .npmrc
中指定 SASS_BINARY_DIR 外,您还可以在 windows.
set SASS_BINARY_DIR=C:\res\node-sass
将其导出为环境变量