Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Npm 错误:将babel与webpack一起使用时模块解析失败_Npm_Webpack_Babeljs - Fatal编程技术网

Npm 错误:将babel与webpack一起使用时模块解析失败

Npm 错误:将babel与webpack一起使用时模块解析失败,npm,webpack,babeljs,Npm,Webpack,Babeljs,当我试图安装babel来使用它的网页包并进行配置时,我会遇到这个错误。我尝试了babel和webpack的不同版本,我尝试了很多配置,但没有一个有效,它们总是抛出相同的错误。 注意:我已经有了另一个插件,比如WebpackServer和WebpackHTML,但我很确定它们不会影响babel ERROR in ./node_modules/core-js/modules/es6.regexp.exec.js 1:3 Module parse failed: Unexpected characte

当我试图安装babel来使用它的网页包并进行配置时,我会遇到这个错误。我尝试了babel和webpack的不同版本,我尝试了很多配置,但没有一个有效,它们总是抛出相同的错误。 注意:我已经有了另一个插件,比如WebpackServer和WebpackHTML,但我很确定它们不会影响babel

ERROR in ./node_modules/core-js/modules/es6.regexp.exec.js 1:3
Module parse failed: Unexpected character ' ' (1:3)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
 @ ./node_modules/core-js/es6/index.js 102:0-37
 @ ./node_modules/@babel/polyfill/lib/noConflict.js
 @ ./node_modules/@babel/polyfill/lib/index.js
 @ multi @babel/polyfill ./src/js/index.js
.LRC文件:

// projectname/.babelrc
{
    "presets": [
     [ "@babel/preset-env", {
       "modules": false,
       "targets": {
        "browsers": [
          "last 2 Chrome versions",
          "last 2 Firefox versions",
          "last 2 Safari versions",
          "last 2 iOS versions",
          "last 1 Android version",
          "last 1 ChromeAndroid version",
          "ie 11"
        ]
       }
     } ]
    ]
}
webpack.config.js文件:

// webpack.config.js
const path = require( 'path' );
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    context: __dirname,
    entry: ['@babel/polyfill', './src/js/index.js'],
    output: {
        path: path.resolve( __dirname, 'dist' ),
        filename: 'js/bundle.js',
    },
    devServer: {
        contentBase: './dist'
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: './src/index.html'
        })
    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: 'babel-loader'
            }
        ]
    }
};
package.json文件:

{
  "name": "forkify",
  "version": "1.0.0",
  "description": "forkify project",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development",
    "build": "webpack --mode production",
    "start": "webpack-dev-server --mode development --open"
  },
  "author": "Ahmed Hossam",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.6.4",
    "@babel/core": "^7.6.4",
    "@babel/preset-env": "^7.6.3",
    "babel-loader": "^8.0.6",
    "html-webpack-plugin": "^3.2.0",
    "path": "^0.12.7",
    "webpack": "^4.41.2",
    "webpack-cli": "^3.3.9",
    "webpack-dev-server": "^3.9.0"
  },
  "dependencies": {
    "@babel/polyfill": "^7.6.0"
  }
}