Webpack 4:在输入模块中找不到错误:错误:无法解析“ ./src”

时间:2018-08-12 16:14:50

标签: webpack

这是一个重复的问题,但我想使用自定义条目,而不是帖子Webpack 4: Error in entry

中所建议的默认Webpack 4条目

webpack.dev.config.js:

import path from 'path';

export default {
  mode: 'development',
  entry: [
    'babel-polyfill',
    './app/components/index.js'
  ],
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      { test: /\.js$/, exclude: /node_modules/, use: 'babel-loader' }
    ]
  }
};

Project Structure

运行 webpack-wd

时显示以下错误
  

参数数量不足或找不到条目。或者,运行   “ webpack(-cli)--help”以获取使用信息。

     

找不到入口模块中的错误:错误:无法解析“ ./src”   'C:\ Patient_Check_In'

1 个答案:

答案 0 :(得分:0)

使用commonJS模块语法进行Webpack配置:

webpack.config.js

const path = require('path');

module.exports = {
  mode: 'development',
  entry: [
    'babel-polyfill',
    './app/components/index.js'
  ],
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: 'babel-loader'
      }
    ]
  }
}

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "scripts": {
    "build": "webpack"
  },
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "webpack": "^4.16.5",
    "webpack-cli": "^3.1.0"
  },
  "dependencies": {
    "babel-polyfill": "^6.26.0"
  }
}

app / compontens / index.js

console.log('hello!');

如果您运行webpack,则会在 dist 文件夹中生成一个名为 bundle.js 的文件,该文件将包含所有babel pollyfills,Webpack运行时以及您的应用程序(在本例中为简单的console.log语句)。如果需要,可以设置特定的babel配置。