问答详情
源自:2-1 class类定义语法

我的一运行就报错

http://img2.mukewang.com/5da8105100014a6613390366.jpg

babel-loader 我也安装了7的版本 

提问者:qq_carry型选手_0 2019-10-17 14:56

个回答

  • lap
    2020-08-23 16:14:17

    "@babel/core": "^7.11.4",    "@babel/plugin-proposal-class-properties": "^7.10.4",    "@babel/preset-env": "^7.11.0",    "babel-loader": "^8.1.0",    "webpack": "^4.44.1",    "webpack-cli": "^3.3.12"


  • 婧婧浩浩
    2020-07-07 11:35:53

    有没有最新的配置文件发一下呀?

  • 一米阳光0704
    2019-12-09 21:59:07

    npm i babel-loader@7.1.4

  • 3DX退之
    2019-10-18 11:17:02

    安装了7的版本会报错的。您可以看一下关于babel7安装指南。

    主要原因是babel7后默认的loader的名字变了。

    这里是验证后的配置

    package.json

    {

      "name": "demo-mobx",

      "version": "1.0.0",

      "description": "",

      "main": "webpack.config.js",

      "scripts": {

        "start": "webpack -w",

        "test": "echo \"Error: no test specified\" && exit 1"

      },

      "keywords": [],

      "author": "",

      "license": "ISC",

      "devDependencies": {

        "@babel/cli": "^7.6.4",

        "@babel/core": "^7.6.4",

        "@babel/plugin-proposal-class-properties": "^7.5.5",

        "@babel/plugin-proposal-decorators": "^7.6.0",

        "@babel/plugin-proposal-object-rest-spread": "^7.6.2",

        "@babel/plugin-transform-runtime": "^7.6.2",

        "@babel/preset-env": "^7.6.3",

        "@babel/preset-react": "^7.6.3",

        "babel-loader": "^8.0.6",

        "babel-preset-mobx": "^2.0.0",

        "webpack": "^4.41.2",

        "webpack-cli": "^3.3.9"

      },

      "dependencies": {

        "@babel/polyfill": "^7.6.0",

        "mobx": "^5.14.0",

        "mobx-react": "^6.1.4",

        "prop-types": "^15.7.2",

        "react": "^16.10.2",

        "react-dom": "^16.10.2"

      }

    }



    webpack.config.js

    const path = require('path');

    const config = {

      mode: 'development',

      entry: path.resolve(__dirname, 'src/index.js'),

      output: {

        path: path.resolve(__dirname, 'dist'),

        filename: 'main.js'

      },

      module: {

        rules:[

          {

            test: /\.js|jsx$/,

            exclude: /node_modules/,

            use: {

              loader: 'babel-loader',

              options: {

                presets: [

                  "@babel/preset-env",

                  "@babel/preset-react",

                  "mobx"

                ],

                plugins: [

                  ["@babel/plugin-proposal-decorators", { "legacy": true }],

                  ["@babel/plugin-proposal-class-properties", { "loose": true }],

                  "@babel/plugin-proposal-object-rest-spread"

                ]

              }

            }

          }

        ]

      },

      devtool: 'inline-source-map'

    }

    module.exports = config;