我正在尝试在终端中运行 npm start,但它不起作用
Posted
技术标签:
【中文标题】我正在尝试在终端中运行 npm start,但它不起作用【英文标题】:I am trying to run npm start in my terminal, but it isn't working 【发布时间】:2022-01-07 22:48:29 【问题描述】:我正在尝试运行 npm start
来开始一个新的 React 项目,但它不工作。我已经这样做了很多次,但现在我收到以下错误:
Starting the development server...
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 (/Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/webpack/lib/util/createHash.js:135:53)
at NormalModule._initBuildHash (/Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/webpack/lib/NormalModule.js:417:16)
at handleParseError (/Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/webpack/lib/NormalModule.js:471:10)
at /Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/webpack/lib/NormalModule.js:503:5
at /Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/webpack/lib/NormalModule.js:358:12
at /Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/loader-runner/lib/LoaderRunner.js:373:3
at iterateNormalLoaders (/Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
at iterateNormalLoaders (/Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
/Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/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 (/Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/webpack/lib/util/createHash.js:135:53)
at NormalModule._initBuildHash (/Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/webpack/lib/NormalModule.js:417:16)
at /Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/webpack/lib/NormalModule.js:452:10
at /Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/webpack/lib/NormalModule.js:323:13
at /Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/loader-runner/lib/LoaderRunner.js:367:11
at /Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/loader-runner/lib/LoaderRunner.js:233:18
at context.callback (/Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at /Users/EgorUlybin/Desktop/Programming/practice folder/React/routing/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'
Node.js v17.2.0
EgorUlybin@MacBook-Pro routing %
在浏览器中,我得到的错误信息是:
无法访问该网站 localhost 拒绝连接。
【问题讨论】:
请在此处分享您的 package.json 文件。 【参考方案1】:可能是 NodeJS 版本的原因。
通过 nvm 将您的 NodeJS 版本从 Current (17) 降级到 LTS (16) 版本。
【讨论】:
我刚刚安装了 node.js 的 v.16 并且它工作正常!为什么 v.17 不起作用? 我想在较新的版本中存在一些依赖问题并阻止了一些要求。因此,请确保在创建实时应用程序时始终使用 LTS 版本。 欢迎您@EgorUlybin 我已经尝试使用 16.13.1 和 14.18.1 版本,但仍然遇到同样的错误。有什么想法吗?【参考方案2】:我找到了解决此问题的方法。
只需使用 yarn create-react-app my-app
创建一个新的 React 应用,然后复制 node_modules
文件夹并用它替换您之前的 React 应用 node_modules
文件。
【讨论】:
以上是关于我正在尝试在终端中运行 npm start,但它不起作用的主要内容,如果未能解决你的问题,请参考以下文章
在我尝试在终端上运行 npm start 后,React Native 没有在 chrome 上启动 Metro bundler