简体   繁体   English

尝试 yarn start 时如何解决 Web 重要错误?

[英]How can I solve web vital error when I try yarn start?

I created a React app by Yarn, but when I tried to start I got this error below.我通过 Yarn 创建了一个 React 应用程序,但是当我尝试启动时,出现以下错误。 This is happening with all my applications.我所有的应用程序都会发生这种情况。

yarn start
yarn run v1.22.17
warning ../package.json: No license field
$ react-scripts start
node:internal/modules/cjs/loader:488
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in /home/barry/state/node_modules/postcss-safe-parser/node_modules/postcss/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:416:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:669:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/barry/state/node_modules/postcss-safe-parser/lib/safe-parser.js:1:17) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v17.0.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I've tried npm i web-vitals --save-dev and yarn add -D web-vitals but it does not work anymore.我试过npm i web-vitals --save-devyarn add -D web-vitals但它不再工作了。

I've tried yarn add -g web-vitals too.我也试过yarn add -g web-vitals

There is an ongoing issue related to Create React App and builds with Node v17.有一个与 Create React App 和使用 Node v17 构建相关的持续问题。

See create-react-app #11565参见create-react-app #11565

Try node --version to see which version of node you are using.尝试node --version以查看您使用的节点版本。 If it is a v17+, then you are likely hitting this bug.如果它是 v17+,那么您可能会遇到此错误。

To get around the issue, you can use a version of Node < v17, delete node_modules folder and the lockfile of whichever system you're using — yarn.lock or package-lock.json — then reinstall dependencies.要解决此问题,您可以使用 Node < v17 版本,删除 node_modules 文件夹和您使用的任何系统的锁文件( yarn.lockpackage-lock.json) ,然后重新安装依赖项。

try:尝试:

yarn upgrade

fixed the bug for me, and React App started working.为我修复了错误,React App 开始工作。

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

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