简体   繁体   English

运行 npm start 一直显示错误

[英]running npm start keeps showing errors

Every time i try running npm start on my windows powershell for my react project it keeps showing me errors每次我尝试在我的 Windows PowerShell 上为我的 React 项目运行 npm start 时,它都会向我显示错误

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at module.exports (C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\webpack\lib\NormalModule.js:471:10)
    at C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\webpack\lib\NormalModule.js:503:5
    at C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\webpack\lib\NormalModule.js:358:12
    at C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at iterateNormalLoaders (C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\react-scripts\scripts\start.js:19
  throw err;
  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at module.exports (C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\webpack\lib\NormalModule.js:417:16)
    at C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\webpack\lib\NormalModule.js:452:10
    at C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\webpack\lib\NormalModule.js:323:13
    at C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\loader-runner\lib\LoaderRunner.js:367:11
    at C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\loader-runner\lib\LoaderRunner.js:233:18
    at context.callback (C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
    at C:\Users\user\Documents\Fashola\Web-Development\app-project\node_modules\babel-loader\lib\index.js:59:103 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'

And also what does that reason: 'unsupported' mean?还有这个原因是什么:“不受支持”是什么意思?

If you're using Webpack (which it appears OP is using from their stack trace) and Node 17, there have been some compatibility issues.如果您使用的是 Webpack(似乎 OP 正在从其堆栈跟踪中使用)和 Node 17,则存在一些兼容性问题。 Node 17 changed from OpenSSL 1.1 to 3.0, and there were some breaking changes causing a bug in Webpack. Node 17 从 OpenSSL 1.1 更改为 3.0,并且有一些重大更改导致 Webpack 中出现错误。 There appear to a couple of solutions to this problem.这个问题似乎有几个解决方案。

Option 1: Update Webpack.选项 1:更新 Webpack。

Version 5.61.0 fixes this bug. 5.61.0版修复了这个错误。 This is the easiest solution.这是最简单的解决方案。

If you're on Webpack 4, the developers have no intention to create a bugfix for this version.如果您使用的是 Webpack 4,则开发人员无意为此版本创建错误修复。 You will have to either update to version 5 or use option 3/4 below.您必须更新到版本 5 或使用下面的选项 3/4。

Option 2: Update webpack.config.js .选项 2:更新webpack.config.js

For webpack>=5.54 , you can manually change the hashing algorithm to one that works with OpenSSL 3.0.对于webpack>=5.54 ,您可以手动将哈希算法更改为适用于 OpenSSL 3.0 的哈希算法。

module.exports = {
    output: {
        hashFunction: 'xxhash64'
    }
}

Option 3: Downgrade Node.选项 3:降级节点。

Changing to an LTS version of Node (currently 16.x) should resolve the problem for now.更改为 LTS 版本的 Node(当前为 16.x)应该可以解决现在的问题。 However, this doesn't solve the problem, it only delays the problem.然而,这并不能解决问题,只会拖延问题。

Option 4: Change NODE_OPTIONS选项 4:更改NODE_OPTIONS

For any version of Webpack with Node 17, you can set a flag to revert to the old OpenSSL API.对于任何带有 Node 17 的 Webpack 版本,您都可以设置一个标志来恢复到旧的 OpenSSL API。 This isn't ideal, but it works.这并不理想,但它有效。

# Works in *nix shells
NODE_OPTIONS='--openssl-legacy-provider' npm start

# ============================
# or (cross-platform solution)
# ============================

# requires installing `cross-env`
npm install -D cross-env

# then...
cross-env NODE_OPTIONS='--openssl-legacy-provider' npm start

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM