是否可以安装 node-sass 离线代理
Is this possible to install node-sass offline proxy
我正在尝试使用 npm 安装 node-sass 模块,但每次都会显示有关网络配置问题的错误,这是因为我正在使用代理和私有注册表,这是错误:
This is most likely not a problem with node-gyp or the package itself and is related to network connectivity In most cases you are behind a proxy or have bad network setting
是否可以离线安装此模块?
我在尝试在公司代理后面安装 node-sass 时遇到了类似的问题。
您可以尝试的是:
- 从这里下载到本地:https://github.com/sass/node-sass/releases(根据你的OS选择合适的)
使用二进制配置参数–sass-binary-path。安装它。
npm install --sass-binary-path="C:\src\v4.7.2\win32-x64-57_binding.node"
How-to
在此处下载二进制文件:https://github.com/sass/node-sass/releases
它因您的 OS 和节点版本而异。
设置环境变量(参见https://github.com/sass/node-sass#binary-configuration-parameters)
export SASS_BINARY_PATH=<absolute_path_to_file>
将<absolute_path_to_file>
替换为您下载的文件的路径。路径应该是绝对的,并且是 linux 格式(如果你使用 git bash,用 cmd 使用 Windows 格式)。要获得绝对路径,您可以转到该目录,打开 git bash 控制台并执行 pwd
,附加文件名,您应该有类似 /c/Users/you/SOFTWARE/win32-x64-64_binding.node
的内容。
安装(本地)
npm i node-sass --save
您需要使用 node-sass 为每个打开的终端导出一次变量。这意味着您应该将导出行添加到 npm start
。 (所以你必须把你下载的文件保存在安全的地方)。
例如,您可以 "start:dev": "set SASS_BINARY_PATH=%cd%\win32-x64-64_binding.node && npm start"
。在这种情况下,sass 二进制文件在我的项目中,使新协作者更容易。我们使用 set
而不是 export
因为 Jetbrain IDE 默认使用 cmd(Windows 终端)。
其他
如果您收到如下错误消息:
Testing binary
Binary has a problem: Error: The module '\?\C:\Users\myself\SOFTWARE\win32-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
这意味着它找到了你的二进制文件,但你为当前的节点版本选择了错误的二进制文件。下载正确的版本,并再次执行上述步骤。
在使用 npm start 时,如果你有(用于 react-script 项目):
./src/product-card-list/product-card-list.component.module.scss (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-6-1!./node_modules/postcss-loader/src??postcss!./node_modules/sass-loader/lib/loader.js??ref--6-oneOf-6-3!./src/product-card-list/product-card-list.component.module.scss)
Error: ENOENT: no such file or directory, scandir 'C:\Users\myself\PROJECTS\advisor_spa\node_modules\node-sass\vendor'
第 4 步失败。再次导出 SASS_BINARY_PATH
应该可以。
如果您使用 Webstorm,您可以为 npm start
进行 运行 配置并添加完整路径 SASS_BINARY_PATH=C:\Users\myself\SOFTWARE\win32-x64-64_binding.node
环境变量(对于 Windows)。
如果您在 Windows 上使用 Visual Code,您可以添加一个系统环境变量,与 PATH 处于同一级别(不在 PATH 内部)。
我正在尝试使用 npm 安装 node-sass 模块,但每次都会显示有关网络配置问题的错误,这是因为我正在使用代理和私有注册表,这是错误:
This is most likely not a problem with node-gyp or the package itself and is related to network connectivity In most cases you are behind a proxy or have bad network setting
是否可以离线安装此模块?
我在尝试在公司代理后面安装 node-sass 时遇到了类似的问题。
您可以尝试的是:
- 从这里下载到本地:https://github.com/sass/node-sass/releases(根据你的OS选择合适的)
使用二进制配置参数–sass-binary-path。安装它。
npm install --sass-binary-path="C:\src\v4.7.2\win32-x64-57_binding.node"
How-to
在此处下载二进制文件:https://github.com/sass/node-sass/releases 它因您的 OS 和节点版本而异。
设置环境变量(参见https://github.com/sass/node-sass#binary-configuration-parameters)
export SASS_BINARY_PATH=<absolute_path_to_file>
将<absolute_path_to_file>
替换为您下载的文件的路径。路径应该是绝对的,并且是 linux 格式(如果你使用 git bash,用 cmd 使用 Windows 格式)。要获得绝对路径,您可以转到该目录,打开 git bash 控制台并执行 pwd
,附加文件名,您应该有类似 /c/Users/you/SOFTWARE/win32-x64-64_binding.node
的内容。
安装(本地)
npm i node-sass --save
您需要使用 node-sass 为每个打开的终端导出一次变量。这意味着您应该将导出行添加到
npm start
。 (所以你必须把你下载的文件保存在安全的地方)。
例如,您可以 "start:dev": "set SASS_BINARY_PATH=%cd%\win32-x64-64_binding.node && npm start"
。在这种情况下,sass 二进制文件在我的项目中,使新协作者更容易。我们使用 set
而不是 export
因为 Jetbrain IDE 默认使用 cmd(Windows 终端)。
其他
如果您收到如下错误消息:
Testing binary
Binary has a problem: Error: The module '\?\C:\Users\myself\SOFTWARE\win32-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
这意味着它找到了你的二进制文件,但你为当前的节点版本选择了错误的二进制文件。下载正确的版本,并再次执行上述步骤。
在使用 npm start 时,如果你有(用于 react-script 项目):
./src/product-card-list/product-card-list.component.module.scss (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-6-1!./node_modules/postcss-loader/src??postcss!./node_modules/sass-loader/lib/loader.js??ref--6-oneOf-6-3!./src/product-card-list/product-card-list.component.module.scss)
Error: ENOENT: no such file or directory, scandir 'C:\Users\myself\PROJECTS\advisor_spa\node_modules\node-sass\vendor'
第 4 步失败。再次导出 SASS_BINARY_PATH
应该可以。
如果您使用 Webstorm,您可以为 npm start
进行 运行 配置并添加完整路径 SASS_BINARY_PATH=C:\Users\myself\SOFTWARE\win32-x64-64_binding.node
环境变量(对于 Windows)。
如果您在 Windows 上使用 Visual Code,您可以添加一个系统环境变量,与 PATH 处于同一级别(不在 PATH 内部)。