我在学习 Next.js 时遇到此错误,根据此处的站点文档 https://nextjs.org/docs/api-reference/create-next-app 使用 npx create-next-app
命令。一切正常,直到我启动服务器,
错误堆栈:
$ npm run dev
> devto-clone@0.1.0 dev
> next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:130:10)
at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:130:10)
at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
node:internal/crypto/hash:67
this[kHandle] = new _Hash(algorithm, xofLen);
^
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:130:10)
at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5 {
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
Node.js v17.0.1
包.json:
{
"name": "devto-clone",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "11.1.2",
"react": "17.0.2",
"react-dom": "17.0.2"
},
"devDependencies": {
"eslint": "7.32.0",
"eslint-config-next": "11.1.2"
}
}
原文由 Yuza 发布,翻译遵循 CC BY-SA 4.0 许可协议
我找到了这个解决方案 https://github.com/webpack/webpack/issues/14532
如果使用 bash,则在任何命令之前运行
NODE_OPTIONS=--openssl-legacy-provider
添加
NODE_OPTIONS=--openssl-legacy-provider
到 package.json编辑
就我而言,我使用的是 Nodejs 17.0.1 版本并导致此错误。
首先,我在 GitBash Windows 中的任何命令之前使用此命令
export NODE_OPTIONS=--openssl-legacy-provider
来解决此问题。但是,我认为这不是一种有效的方法,所以我要做的是: