node.js 找不到模块 babel-preset-es2015

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52889188/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:55:33  来源:igfitidea点击:

Cannot find module babel-preset-es2015

node.jsreactjs

提问by j sharma

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

再次出现同样的错误:Error: Cannot find module 'babel-preset-es2015'.

Full error log:

完整的错误日志:

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]

回答by Pretseli

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

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

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

从错误来看,您似乎使用的是版本 7。es20XX-presets已弃用,因此我建议您切换到@babel/preset-env.

First install the preset (using npm):

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

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

Then add the preset to your .babelrc

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

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

回答by Yan Pak

Thing in that the babel 7 uses @babel/preset-env. Other presets are deprecated Here saying about this https://babeljs.io/docs/en/v7-migration#yearly-preset-deprecations-blog-2017-12-27-nearing-the-70-releasehtml-deprecated-yearly-presets-eg-babel-preset-es20xx

babel 7 使用的东西@babel/preset-env。其他预设已弃用 这里说这个https://babeljs.io/docs/en/v7-migration#yearly-preset-deprecations-blog-2017-12-27-nearing-the-70-releasehtml-deprecated-yearly-预设-eg-babel-preset-es20xx

You should specify in a configuration file (I don't know if you are using Webpack or something else) preset as "@babel/preset-env". Install it through npm install --save-dev @babel/preset-env

您应该在配置文件中指定(我不知道您使用的是 Webpack 还是其他东西)预设为“@babel/preset-env”。安装通过npm install --save-dev @babel/preset-env

For example, you are using Webpack module bundler. In that case, specify like this:

例如,您正在使用 Webpack 模块捆绑器。在这种情况下,请指定如下:

use: {
      loader: "babel-loader",
      options: {
                presets: ["@babel/preset-env"]
      }
}

Here is a documentation https://webpack.js.org/loaders/babel-loader/if you suddenly will need.

如果您突然需要,这里有一个文档https://webpack.js.org/loaders/babel-loader/

Happy coding!

快乐编码!

回答by Mr.Bhat

The error log clearly says that it can not find the module. Cannot find module 'babel-preset-es2015' from 'C:\Users\hp\Desktop\reactApp' at Function.module.exports [as sync]Just run this command to install packages

错误日志清楚地表明它找不到模块。Cannot find module 'babel-preset-es2015' from 'C:\Users\hp\Desktop\reactApp' at Function.module.exports [as sync]只需运行此命令即可安装软件包

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

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

Also check your .babelrc

还要检查你的 .babelrc

More information here - > https://babeljs.io/docs/en/babel-preset-es2015

更多信息在这里 - > https://babeljs.io/docs/en/babel-preset-es2015