gpt4 book ai didi

javascript - 错误 [ERR_MODULE_NOT_FOUND] : Cannot find package '@babel/plugin-preset-react' imported from

转载 作者:行者123 更新时间:2023-12-05 03:28:41 25 4
gpt4 key购买 nike

当我运行命令来构建 react 项目时:

yarn build

显示错误:

➜  react-admin git:(master) ✗ yarn build
yarn run v1.22.17
$ webpack --mode production --config config/webpack.build.config.js
assets by status 1.48 KiB [cached] 1 asset
./src/index.js 39 bytes [built] [code generated] [1 error]

ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@babel/plugin-preset-react' imported from /Users/xiaoqiangjiang/source/reddwarf/frontend/react-admin/babel-virtual-resolve-base.js
at new NodeError (/Users/xiaoqiangjiang/source/reddwarf/frontend/react-admin/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:2552:5)
at packageResolve (/Users/xiaoqiangjiang/source/reddwarf/frontend/react-admin/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:3208:9)
at moduleResolve (/Users/xiaoqiangjiang/source/reddwarf/frontend/react-admin/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:3242:18)
at defaultResolve (/Users/xiaoqiangjiang/source/reddwarf/frontend/react-admin/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:3281:13)
at /Users/xiaoqiangjiang/source/reddwarf/frontend/react-admin/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:3304:14
at Generator.next (<anonymous>)
at asyncGeneratorStep (/Users/xiaoqiangjiang/source/reddwarf/frontend/react-admin/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:63:103)
at _next (/Users/xiaoqiangjiang/source/reddwarf/frontend/react-admin/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:65:194)
at /Users/xiaoqiangjiang/source/reddwarf/frontend/react-admin/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:65:364
at new Promise (<anonymous>)

我尝试删除 node_modules 文件夹并重新安装,但没有成功。这是关于 babel 的 package.json:

    "@babel/core": "^7.17.5",
"@babel/preset-react": "^7.16.7",
"@fingerprintjs/fingerprintjs": "^3.3.2",
"@svgr/webpack": "4.3.3",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"animate.css": "^3.7.2",
"antd": "^4.17.4",
"axios": "^0.19.0",
"babel-eslint": "10.1.0",
"babel-jest": "^24.9.0",
"babel-loader": "^8.2.3",
"babel-plugin-named-asset-import": "^0.3.6",
"babel-preset-react-app": "^9.1.2",

为什么会出现这个错误?我应该怎么做才能解决这个问题?我已经尝试过这个命令:

yarn add babel-preset-react

最佳答案

它可能缺少 babel 的配置文件。您能否尝试添加 babel 配置文件并在其中添加此代码(引用 babel 配置链接 https://babeljs.io/docs/en/config-files)

{
"presets": ["@babel/preset-react"]
}

关于javascript - 错误 [ERR_MODULE_NOT_FOUND] : Cannot find package '@babel/plugin-preset-react' imported from,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71194627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com