在执行npm install时,使用node-sass时出现命令失败(升级到Node.js 14到18的备忘录)

请提供更多上下文信息以便准确理解并回答您的问题。

    【簡単】Node.jsにsassをインストールする手順 – Qiita

错误的node-sass

npm 错误!命令执行失败
npm 错误!命令 C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js

查看 package.json 文件

"node-sass": "^4.14.1",

这是一个问题。这个代码只适用于nodejs 14版本。下面是可运行的版本清单。由于你安装的是nodejs 18版本,所以出错了。

以下是Node.js 18的兼容性。

- "node-sass": "^4.14.1",
+ "node-sass": "^8.0.0",

一起更新sass-loader。
因为webpack 4系只支持sass-loader 10及以下版本,所以需要指定为10。
参考: 在Nuxt.js中使用Sass时出现“TypeError: this.getOptions is not a function”错误 | cly7796.net

- "sass-loader": "^8.0.2",
+ "sass-loader": "^10.0.0",

由于没有包含缓存加载程序,因此添加了它。

运行npm run serve时出现找不到cache-loader的错误。

    package-lock.json には 記載されていたが、 package.jsonにはなかったので追加

依赖-只需要一個選項

+ "cache-loader": "^4.1.0",

openssl_fips 未定义错误对应解决方案

npm错误!在尝试加载binding.gyp时,评估条件“openssl_fips !=“”,未定义’openssl_fips’名称。

Unable to target older node versions with node.js 17 · Issue #2534 · nodejs/node-gyp

node_modules/node-gyp/gyp/pylib/gyp/input.py

- env = {"__builtins__": {}, "v": StrictVersion}
+ env = {"__builtins__": {"openssl_fips": ""}, "v": StrictVersion}

启动调试的方法

用这种方法,构建是成功的。然而,无法启动调试模式。出现了“electron: –openssl-legacy-provider is not allowed in NODE_OPTIONS”错误,导致无法运行。

    vue-cli-plugin-electron-builder でセットアップしたElectronプロジェクトがビルドできない – Qiita

发生了与上述相同的现象。

在 vue.config.js 文件的开头添加以下内容

const crypto = require('crypto');
/**
 * md4 algorithm is not available anymore in NodeJS 17+ (because of + lib SSL 3).
 * In that case, silently replace md4 by md5 algorithm.
 */
try {
  crypto.createHash('md4');
} catch (e) {
  console.warn('Crypto "md4" is not supported anymore by this Node + + version');
  const origCreateHash = crypto.createHash;
  crypto.createHash = (alg, opts) => {
    return origCreateHash(alg === 'md4' ? 'md5' : alg, opts);
  };
}
image.png

清除缓存的方法

npm cache clean --force
してから
npm install

关于帽子符号的问题

主次修复

    • キャレット^をつけると、Major は一致し Minor と Patch は指定されたもの以上

 

    チルダ~をつけると、Major と Minor は一致し Patch は指定されたもの以上

Vue.js 开发工具

    Vue.js devtools – Chrome ウェブストア