我已经使用以下命令在我的react项目中添加了预设、react和env:
纱线全球添加babel-预设-react@6.24.1 babel-预设-env@1.5.2
My package.json file has updated the presets and looks like the following:
{
"name": "indecesion-app",
"version": "1.0.0",
"main": "index.js",
"author": "ak",
"license": "MIT",
"dependencies": {
"babel-preset-env": "1.5.2",
"babel-preset-react": "6.24.1"
}
}甚至我的node_modules文件夹也更新了预置。
文件夹结构如下所示:
应用程序(应用程序的文件夹名称)
indecesion-app> babel src/app.js --out-file=public/script/app.js
它显示了错误:
Error: Couldn't find preset "env react" relative to directory "src"
at C:\Users\anil\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:293:19
at Array.map (<anonymous>)
at OptionManager.resolvePresets (C:\Users\anil\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20)
at OptionManager.mergePresets (C:\Users\anil\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10)
at OptionManager.mergeOptions (C:\Users\anil\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14)
at OptionManager.init (C:\Users\anil\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
at File.initOptions (C:\Users\anil\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\index.js:212:65)
at new File (C:\Users\anil\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\index.js:135:24)
at Pipeline.transform (C:\Users\anil\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
at transform (C:\Users\anil\AppData\Roaming\npm\node_modules\babel-cli\lib\babel\util.js:50:22)请提出解决办法
发布于 2020-05-05 10:24:07
我也遇到了同样的问题,我可以通过添加引号来解决这个问题:
babel src/app.js -out-file=public/script/app.js-预设=“env,react”
发布于 2020-05-07 10:07:12
首先,确保安装了以下软件包:
npm安装
然后,运行以下命令:
babel src/app.js -out-file=public/script/app.js-预设=“env,react”
希望这会有所帮助:)
发布于 2020-04-18 02:18:59
我有同样的问题,因为这看起来是Udemy反应课程的一部分。
https://stackoverflow.com/questions/61116908
复制相似问题