提问人:Harj 提问时间:11/16/2023 最后编辑:Helge DerenthalHarj 更新时间:11/21/2023 访问量:19
npm run build on 未知选项:C:\library\my-app\node_modules\babel-preset-react-app\index.js.overrides
npm run build on Unknown option: C:\library\my-app\node_modules\babel-preset-react-app\index.js.overrides
问:
我正在尝试发布一个 react 包,但在构建我的包时失败了。我查看了许多 stackoverflow 和其他提到该问题的互联网网站,但我还没有找到答案。
我的package.json
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-regular-svg-icons": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"moment": "^2.29.4",
"react": "^18.2.0",
"react-datepicker": "^4.21.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"react-select": "^5.8.0",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "cross-env NODE_ENV=production babel src/lib --out-dir dist --copy-files --ignore __tests__,spec.js,test.js,__snapshots__",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"babel-cli": "^6.26.0",
"babel-preset-react": "^6.24.1",
"cross-env": "^7.0.3"
}
}
当我运行 npm run build 时出现错误
ReferenceError: [BABEL] src\lib\program.js: Unknown option: C:\library\my-app\node_modules\babel-preset-react-app\index.js.overrides. Check out http://babeljs.io/docs/usage/options/ for more information about options.
A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:
Invalid:
`{ presets: [{option: value}] }`
Valid:
`{ presets: [['presetName', {option: value}]] }`
我有以下 babel 配置 .巴贝尔
{
"presets": [["react-app", { "absoluteRuntime": false }]]
}
任何帮助,非常感谢
查看了各个网站。删除了node_modules并重新运行了 npm install。仍然没有喜悦。
答:
0赞
Harj
11/16/2023
#1
我似乎养成了一个习惯,先问一个问题,然后自己回答。 我花了 3 天时间在这个问题上尝试了各种事情。我一发布问题,我就读了几篇文章,其中一篇给了我线索。版本号。
从我得到的错误来看,babel 模块似乎与我的设置不兼容。
最初我在package.json有以下内容
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"babel-cli": "^6.26.0",
"babel-preset-react": "^6.24.1",
"cross-env": "^7.0.3"
}
babel-cli 和 babel-preset-react 是错误的版本。我需要的是 babel 模块的作用域版本中的最新版本
"devDependencies": {
"@babel/cli": "^7.23.0",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-react": "^7.23.3",
"cross-env": "^7.0.3"
}
现在一切正常。
我学到了什么?当按照“如何”的示例进行操作时,请检查其日期以及它正在使用的任何内容,看看它是否适合您。
评论