"ReferenceError未知插件“;当我尝试使用babel-cli转换目录中的js文件时

"ReferenceError Unknown plugin" when I try to transform js files in a directory using babel cli

本文关键字:转换 babel-cli 文件 js 插件 未知 ReferenceError quot      更新时间:2023-09-26

我对巴贝尔有些陌生。当我尝试使用以下命令转换目录中的一些.jsx文件时,我成功了:

babel --plugins transform-react-jsx test.js

但是,当我尝试转换目录中的jsx文件列表时,它失败了。以下是命令和错误消息:

babel --plugins transform-react-jsx ../public/js/bundle/temp_realtime/ -d ../public/js/bundle/realtime

ReferenceError: Unknown plugin "transform-react-jsx" specified in "base" at 0, attempted to resolve relative to "../public/js/bundle/temp_realtime"
    at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:193:17
    at Array.map (native)
    at Function.normalisePlugins (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:173:20)
    at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:271:36)
    at OptionManager.init (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:416:10)
    at File.initOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:191:75)
    at new File (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:122:22)
    at Pipeline.transform (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/pipeline.js:42:16)
    at transform (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:53:22)
    at Object.compile (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:62:12)

我不知道为什么会变成这样。插件babel-Plugin-transform-react-jsx已经使用命令安装:

npm install babel-plugin-transform-react-jsx 

这件事发生在我身上是因为我不小心使用了:

{
  "plugins": ["es2015", "react"]
}

我的意思是:

{
  "presets": ["es2015", "react"]
}