javascript 运行 React App 时找不到模块“@babel/plugin-transform-react-jsx-source”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53327625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot find module '@babel/plugin-transform-react-jsx-source' when running React App
提问by AltBrian
I have just created a React App with create-react-app aquastarsand then eject the dependencies using yarn run ejectand when I run the app I get the following error.
我刚刚创建了一个 React 应用程序,create-react-app aquastars然后使用它弹出依赖项yarn run eject,当我运行该应用程序时,出现以下错误。
Cannot find module '@babel/plugin-transform-react-jsx-source'
找不到模块“@babel/plugin-transform-react-jsx-source”
I haven't done anything! What do I need to do to get this up and running? Any help would be appreciated.
我什么都没做!我需要做什么才能启动并运行它?任何帮助,将不胜感激。
回答by Fernando Rojo
The solution by @xiaobowas actually insufficient for me. It took me a while to figure this out after upgrading expo to v32, so here's what I did in case anyone else has the same problem. (Answer from expo forums.)
@xiaobo的解决方案对我来说实际上是不够的。将 expo 升级到 v32 后,我花了一段时间才弄清楚这一点,所以这是我所做的,以防其他人遇到同样的问题。(来自世博论坛的回答。)
If you have a .babelrcfile in the root of your repository, re-name it to something like .babelrc-oldso it doesn't get used.
如果您.babelrc的存储库的根目录中有一个文件,请将其重命名为类似名称,.babelrc-old以免被使用。
Add a file called babel.config.jsto the root of your repository.
添加一个名为babel.config.js您存储库根目录的文件。
Put this in the babel.config.js file:
把它放在 babel.config.js 文件中:
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
All set!
可以了,好了!
回答by xiaobo
After you execute npm run eject:
执行后npm run eject:
cd /your/project/path(ignore)rm -rf node_modulesnpm install(don't use yarn )npm run start success
cd /your/project/path(忽略)rm -rf node_modulesnpm install(不要使用纱线)npm run start success
回答by RKM
Delete the whole node_modulesand re-run yarnto make it work.
rm -R node_modules/
rm yarn.lock
yarn install
删除整个node_modules并重新运行yarn以使其工作。
rm -R node_modules/
rm yarn.lock
yarn install
回答by Gildo Vargas
In my case, it was solved by installing, on Reactjs, "@babel", @babel/plugin-transform-react-jsx
就我而言,它是通过在 Reactjs 上安装“@babel”来解决的, @babel/plugin-transform-react-jsx
1: yarn add @babel/plugin-transform-react-jsx
2: yarn start
1: yarn add @babel/plugin-transform-react-jsx
2:yarn start
回答by Risen human
Try to replace '@babel/plugin-transform-react-jsx-source' with '@babel/transform-react-jsx-source'
尝试将 '@babel/plugin-transform-react-jsx-source' 替换为 '@babel/transform-react-jsx-source'
回答by ham118
Vanished this error after just changed the name of “.babelrc”filewhich was at the root of the repository.
经过短短消失了这个错误改的名字“.babelrc”文件这是在库的根。

