首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >env:无法找到与目录"src“相关的预设"env env”。

env:无法找到与目录"src“相关的预设"env env”。
EN

Stack Overflow用户
提问于 2020-04-09 08:25:04
回答 9查看 3K关注 0票数 8

我已经使用以下命令在我的react项目中添加了预设、react和env:

纱线全球添加babel-预设-react@6.24.1 babel-预设-env@1.5.2

代码语言:javascript
复制
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文件夹也更新了预置。

文件夹结构如下所示:

应用程序(应用程序的文件夹名称)

  • node_modules
  • 公共的
  • src
  • package.json
  • yarn.lock 现在当我运行命令时

indecesion-app> babel src/app.js --out-file=public/script/app.js

它显示了错误:

代码语言:javascript
复制
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)

请提出解决办法

EN

回答 9

Stack Overflow用户

发布于 2020-05-05 10:24:07

我也遇到了同样的问题,我可以通过添加引号来解决这个问题:

babel src/app.js -out-file=public/script/app.js-预设=“env,react”

票数 23
EN

Stack Overflow用户

发布于 2020-05-07 10:07:12

首先,确保安装了以下软件包:

npm安装

然后,运行以下命令:

babel src/app.js -out-file=public/script/app.js-预设=“env,react”

希望这会有所帮助:)

票数 4
EN

Stack Overflow用户

发布于 2020-04-18 02:18:59

我有同样的问题,因为这看起来是Udemy反应课程的一部分。

  1. 删除所有与Babel相关的全球NPM/Yarn模块。在Windows上,地雷在c:\user\user\appdata\漫游\npm\no解调器中显示,因为它是全局安装的。
  2. 项目中的npm
  3. npm安装
  4. npm安装
  5. npx .\src\app.js -o .\public\scripts\app.js -预设=@ babel /预设-env,@babel/预设-反应
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61116908

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档