首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react,wepack,babel,node,npm启动错误

react,wepack,babel,node,npm启动错误
EN

Stack Overflow用户
提问于 2018-12-25 16:31:51
回答 1查看 497关注 0票数 0

./main.js中的错误

模块构建失败(来自./node_node/babel-加载程序/lib/index.js): 错误:无法从“F:\reactapp”中找到模块“@babel/预设-es2015” 在Function.module.exports as sync 在(F:\reactapp\node_modules@babel\core\lib\config\files\plugins.js:101:31) resolveStandardizedName 在(F:\reactapp\node_modules@babel\core\lib\config\files\plugins.js:58:10) resolvePreset 在(F:\reactapp\node_modules@babel\core\lib\config\files\plugins.js:77:20) loadPreset 在(F:\reactapp\node_modules@babel\core\lib\config\config-descriptors.js:154:9) createDescriptor 在(F:\reactapp\node_modules@babel\core\lib\config\config-descriptors.js:109:50) items.map 在(F:\reactapp\node_modules@babel\core\lib\config\config-descriptors.js:109:29) Array.map () 在(F:\reactapp\node_modules@babel\core\lib\config\config-descriptors.js:101:10) createPresetDescriptors 在(F:\reactapp\node_modules@babel\core\lib\config\config-descriptors.js:58:96) passPerPreset @ multi (webpack)-dev-server/client?http://localhost:8080 (Webpack)/index.html/dev-server.js ./main.js main2 Child html-index.html插件: 1项资产 入口点未定义= index.html ./node_modules/html-webpack-plugin/lib/loader.js!./index.html 448字节{0}构建了527 KiB {0} built (webpack)/buildin/global.js 472字节{0}构建(webpack)/buildin/module.js 497字节{0} built i ?wdm?:编译失败。终止批处理作业(Y/N)?

package.json文件:

包json文件如下所示。我跟着setup.htm

代码语言:javascript
复制
{
  "name": "reactapp",
  "version": "1.0.0",
  "description": "demo project",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --mode development --open --hot",
    "build": "webpack --mode production"
  },
  "keywords": [
    "[]"
  ],
  "author": "manjunathan g",
  "license": "ISC",
  "dependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.2.2",
    "@babel/preset-react": "^7.0.0",
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "webpack": "^4.28.2",
    "webpack-cli": "^3.1.2",
    "webpack-dev-server": "^3.1.14"
  },
  "devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.2.3",
    "@babel/preset-env": "^7.2.3",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.4",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "html-webpack-plugin": "^3.2.0"
  }
}

babel配置:

Babel配置文件如下所示,如下所示:setup.htm

代码语言:javascript
复制
{
  "presets":["env", "react"]
}

webpack配置

webpack配置如下:

代码语言:javascript
复制
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
   entry: './main.js',
   output: {
      path: path.join(__dirname, '/bundle'),
      filename: 'index_bundle.js'
   },
   devServer: {
      inline: true,
      port: 8080
   },
   module: {
      rules: [
         {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
               presets: ['@babel/react', '@babel/es2015'],
               plugins: ['@babel/proposal-class-properties']
            }
         }
      ]
   },
   plugins:[
      new HtmlWebpackPlugin({
         template: './index.html'
      })
   ]
}
EN

回答 1

Stack Overflow用户

发布于 2018-12-25 19:11:21

@babel/preset-es2015包已被废弃,您不能再从NPM安装它。

现在的建议是使用@babel/preset-env代替。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53923986

复制
相关文章

相似问题

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