Webpack和babel-loader-corejs2

时间:2018-09-11 07:40:32

标签: javascript npm webpack babel polyfills

你好,在用webpack和babel-loader编译我的js时出现以下错误

*

  ../vendor/xxx/xxx/assets/js/xxx.js中的

ERROR找不到模块:错误:   无法解析'@ babel / runtime-corejs2 / core-js / object / define-property'   在xxx

*

这是我的webpack.config.js的重要部分

module: {
    rules: [
        {
            test: /\.js$/,
            exclude: /(node_modules)/,
            use: {
                loader: 'babel-loader',
                query: {
                    presets: ['@babel/preset-env'],
                    plugins: [
                        ['@babel/plugin-transform-runtime', {
                            'corejs': 2,
                            'helpers': false,
                            'regenerator': false,
                            'useESModules': false,
                        }]
                    ],
                    cacheDirectory: 'node_modules/.cache/babel-loader'
                }
            }
        },

    ]
},

这是我的package.json

{
"name": "assets-webpack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
    "dev": "./node_modules/webpack/bin/webpack.js --config webpack.development.js",
    "prod": "./node_modules/webpack/bin/webpack.js --config webpack.production.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
    "@babel/core": "^7.0.0",
    "@babel/polyfill": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/runtime-corejs2": "^7.0.0-beta.55",
    "babel-loader": "^8.0.2",
    "expose-loader": "^0.7.5",
    "extract-text-webpack-plugin": "^4.0.0-beta.0",
    "fancybox": "^2.1",
    "file-loader": "^1.1.11",
    "glob": "^7.1.2",
    "jquery": "^2.0",
    "jquery-touchswipe": "^1.6.18",
    "js-cookie": "^2.2.0",
    "node-sass": "^4.9.0",
    "sass-loader": "^7.0.1",
    "sprintf": "^0.1.5",
    "uglifyjs-webpack-plugin": "^1.2.5",
    "webpack": "^4.17.2",
    "webpack-merge": "^4.1.2",
    "webpack-validator": "^3.0.1"
},
"devDependencies": {
    "@babel/plugin-transform-runtime": "^7.0.0",
    "source-map-loader": "^0.2.3",
    "webpack-cli": "^2.1.4"


   }
}

对此有什么想法吗?

0 个答案:

没有答案