找不到Entry模块中的错误:错误:无法解析'babel-loader'

时间:2017-12-21 17:37:12

标签: javascript json node.js reactjs webpack

我是初学者的反应。在设置安装并加载所有依赖项时,我最终运行yield userIds.map(userId => call(fetchUserDetails, userId)); 命令但是这会在未找到Entry模块中生成错误 ERROR:错误:无法解析'babel-loader'中的' C:\ Users \ me \ Documents \ React \ react-playlist'我已正确执行了所有安装步骤。我还附加了项目文件夹的screenshot。我还在全球范围内安装了webpack 3.1 i.0,但这也没有用。我也尝试在package.json文件中插入resolve loaders代码,但这也无效。这是错误picture.

P.S。:我正在关注tutorial

以下是我项目的代码。 Package.json文件:

npm start

Webpack.config.js

{
  "name": "react-playlist",
  "version": "1.0.0",
  "description": "All the course files for the Net Ninja React tutorial playlist on YouTube",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "npm run build",
    "build": "webpack -d && webpack-dev-server --content-base src/ --inline --hot --port 1234"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/iamshaunjp/react-playlist.git"
  },
  "author": "me",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/iamshaunjp/react-playlist/issues"
  },
  "homepage": "https://github.com/iamshaunjp/react-playlist#readme",
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "webpack": "^3.10.0",
    "webpack-dev-server": "^2.9.7"
  }
}

的index.html

var path = require('path');

module.exports = {

    entry: path.resolve(__dirname, 'src') + '/app/index.js',
    output: {
        path: path.resolve(__dirname, 'dist') + '/app',
        filename: 'bundle.js',
        publicPath: '/app/'
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                include: path.resolve(__dirname, 'src'),
                loader: 'babel-loader',
                query: {
                    presets: ['react', 'es2015', 'env']
                }
            },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader'
            }
        ]
    } };

2 个答案:

答案 0 :(得分:2)

当您使用最新版本(3.10.0)时,module.loaders配置的webpack部分似乎适用于webpack的旧版本。这是您使用最新webpack进行配置的方式:

module: {
  rules: [
    { 
      test: /\.js$/,
      include: [
        path.resolve(__dirname, "src")
      ],
      use: {
        loader: 'babel-loader'
      },
      options: {
        presets: ['react', 'es2015', 'env']
      }
    },
    {
       test: /\.css$/,
       use: {
         loader: 'style-loader!css-loader'
       }     
    }
  ]

配置部分here中的文档中描述了所有webpack个选项。

答案 1 :(得分:0)

请查看此帖子以获取详细信息(ERROR in multi) Module not found: Error: Can't resolve 'babel/loader',并执行以下命令:

npm install -D babel-loader @babel/core @babel/preset-env webpack