Babel-loader requires babel-core instead of @babel/core

霸气de小男生 提交于 2020-05-15 10:03:11

问题


I replaced babel-core with @babel/core while babel-loader expects babel-core:

{
  "name": "myproject-ui",
  "version": "1.0.0",
  "description": "User interface for myproject",
  "main": "index.js",
  "scripts": {
    "start": "npx webpack-dev-server",
    "build": "npx webpack",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Hello",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.0.0-rc.2",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0-rc.2",
    "@babel/preset-env": "^7.0.0-rc.2",
    "@babel/preset-react": "^7.0.0-rc.2",
    "babel-loader": "^7.1.5",
    "webpack": "^4.16.5",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.5"
  },
  "babel": {
    "presets": [
      "env",
      "react",
      "@babel/plugin-proposal-object-rest-spread"
    ]
  },
  "dependencies": {
    "axios": "^0.18.0",
    "history": "^4.7.2",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-router-dom": "^4.3.1"
  }
}

and this is my webpack config file:

module.exports = {
  entry: './src/index.js',
  output: {
    path: __dirname,
    publicPath: '/',
    filename: 'bundle.js'
  },
  module: {
    rules: [{
      test: /\.js$/,
      exclude: /node_modules/,
      loader: 'babel-loader'
    }]
  },
  mode: 'development',
  devServer: {
    historyApiFallback: true,
    contentBase: './'
  }
};

I know babel-loader works with babel-core, but what if we want to use @babel/core instead of babel-core?


回答1:


AFAIK you need at least babel-loader@^8.0.0-beta to use babel 7+ with webpack. The stable version of babel-loader is still version 7. use babel-loader@next or specify another beta version of the loader to use.

Here is the latest version on the registry. babel-loader 8.0.0-beta.6



来源:https://stackoverflow.com/questions/51978775/babel-loader-requires-babel-core-instead-of-babel-core

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!