【问题标题】:Webpack 2 not resolving entry point in webpack.config.jsWebpack 2 未解析 webpack.config.js 中的入口点
【发布时间】:2017-05-28 06:58:28
【问题描述】:

我在尝试通过 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 buildwebpack --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,它在那个目录里面。谁能帮我确定我收到此错误的原因?

谢谢!

【问题讨论】:

    标签: javascript node.js webpack webpack-2


    【解决方案1】:

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

    【讨论】:

    • 有趣。我这样做了,我没有收到任何错误。但为什么?如果我将PATHS.src 传递给context 参数,webpack 不是从那个文件路径开始然后寻找入口点吗?如果我打印出PATHS.src 的值,我将得到path/to/project/root/src
    • context 不应该是entry 的属性。将其上移一级。
    • 哇,我的疏忽太大了!谢谢@DraganS
    猜你喜欢
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    相关资源
    最近更新 更多