本文介绍了找不到模块babel-preset-es2015的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再次遇到相同的错误:错误:找不到模块'babel-preset-es2015'.

Getting same error again again: Error: Cannot find module 'babel-preset-es2015'.

完整的错误日志:

ERROR in ./main.js Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module 'babel-preset-es2015' from 'C:\Users\hp\Desktop\reactApp'
 at Function.module.exports [as sync] (C:\Users\hp\Desktop\reactApp\node_modules\resolve\lib\sync.js:43:15)
 at resolveStandardizedName (C:\Users\hp\Desktop\reactApp\node_modules\@babel\core\lib\config\files\plugins.js:101:31)
 at resolvePreset (C:\Users\hp\Desktop\reactApp\node_modules\@babel\core\lib\config\files\plugins.js:58:10)
 at loadPreset (C:\Users\hp\Desktop\reactApp\node_modules\@babel\core\lib\config\files\plugins.js:77:20)
 at createDescriptor (C:\Users\hp\Desktop\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:154:9)
 at items.map (C:\Users\hp\Desktop\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:109:50)
 at Array.map ()
 at createDescriptors (C:\Users\hp\Desktop\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:109:29)
 at createPresetDescriptors (C:\Users\hp\Desktop\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:101:10)
 at passPerPreset (C:\Users\hp\Desktop\reactApp\node_modules\@babel\core\lib\config\config-descriptors.js:58:96) @ multi (webpack)-dev-server/client?http://localhost:8080 (webpack)/hot/dev-server.js ./main.js main[2]

推荐答案

对于Babel版本6,软件包名称为 babel-preset-es2015 ,对于Babel版本7,软件包名称为 @babel/preset-es2015 .

For Babel version 6 the package name is babel-preset-es2015 and for Babel version 7 the package name is @babel/preset-es2015.

从该错误看来,您正在使用版本7.已弃用 es20XX-presets ,因此,我建议您切换到 @ babel/preset-env .

From the error it seems that you're using version 7. The es20XX-presets are deprecated, so I recommend you switch to @babel/preset-env.

首先安装预设(使用 npm ):

First install the preset (using npm):

npm install --save-dev @babel/preset-env

然后将预设添加到您的 .babelrc

Then add the preset to your .babelrc

{
    presets: ["@babel/preset-env"]
}

这篇关于找不到模块babel-preset-es2015的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 17:40