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

时间:2017-01-13 00:31:59

标签: javascript node.js webpack webpack-2

尝试通过webpack 2构建应用程序时收到错误。

我的app文件夹结构如下所示:

/
| - 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,它位于该目录中。任何人都可以帮我确定我收到此错误的原因吗?

谢谢!

1 个答案:

答案 0 :(得分:4)

您是否尝试使用'./src/index.js'