Webpack 2 未解析 webpack.config.js 中的入口点

Webpack 2 not resolving entry point in webpack.config.js

我在尝试通过 webpack 2 构建我的应用程序时收到错误消息。

我的应用程序文件夹结构如下所示:

/
| - dist/
|
| - src/
|   |  
|   | - modules/
|   |   |
|   |   | - module1.js
|   |
|   | - index.js *
|
| _ webpack.config.js
|
| - package.json

我的 webpack.config.js 文件的相关部分在这里:

/**
 * Requires
 */
const path = require('path');


/**
 * Variables
 */
const PATHS = {
  src: path.join(__dirname, 'src'),
  dist: path.join(__dirname, 'dist')
};


/**
 * Configuration
 */
module.exports = {

  entry: {
    context: PATHS.src,
    main: './index.js'
  },

  ....
}

当我 运行 npm run build,这是我 webpack --display-error-details 的脚本别名时,我收到以下错误详细信息:

ERROR in Entry module not found: Error: Can't resolve './index.js' in <my project path>
resolve './index.js' in <my project path>
  using description file: <my project path>/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration

现在,我正在慢慢学习 webpack,这很可能是对 webpack context 属性 工作原理的简单误解。 PATHS.src 等于我项目的 src 目录的绝对路径,我的入口点是 ./index.js,它在该目录内。谁能帮我确定为什么会收到此错误?

谢谢!

你尝试过 './src/index.js'