Webpack 5 错误 - 尽管使用自定义配置和自定义条目值仍尝试加载默认入口点

问题描述 投票:0回答:1

正在从 Webpack v.4 更新到 v.5。

正如标题所示,尽管项目根目录下存在

webpack.config.js
,但 Webpack 会触发错误,因为它无法找到
./src/index.js

./src/index.js
不存在,我指定了一个自定义
entry
(Webpack 会加载)。

当我指定了自定义

./src/index.js
时,Webpack 尝试解决
entry
的任何想法吗?

我的配置文件的内容:

// webpack.config.js
module.exports = [
  {
    mode: 'development',
    entry: '/Users/nathanhouse/Development/marketing-site/src/js/pages/default.js',
    output: {
      filename: 'bundle.js',
    },
  },
  {
    stats: 'verbose',
  },
];

我希望 Webpack 在包含

dist
的项目根部的默认
bundle.js
目录下生成单个文件。

相反,Webpack 会生成

bundle.js
(包含我的入口点代码)和
main.js
下的
dist
。此外,它还会抛出错误,表明无法找到
./src/index.js

我还尝试通过终端指定配置文件(尽管它正在使用该文件,因为它正在编译

default.js

运行 Webpack 的输出(带错误):

asset bundle.js 1.39 KiB [compared for emit] (name: main)
./src/js/pages/default.js 137 bytes [built] [code generated]
webpack 5.91.0 compiled successfully in 80 ms

PublicPath: auto
asset main.js 667 bytes {main} [compared for emit] (name: main)
Entrypoint main 667 bytes = main.js
chunk {main} (runtime: main) main.js (main) [entry] [rendered]
  > ./src main
  

LOG from webpack.Compiler
<t> make hook: 16.242459 ms
<t> finish make hook: 0.047125 ms
<t> finish compilation: 1.108125 ms
<t> seal compilation: 9.281625 ms
<t> afterCompile hook: 0.032792 ms
<t> emitAssets: 2.9205 ms
<t> emitRecords: 0.047 ms
<t> done hook: 0.09125 ms
<t> beginIdle: 0.016917 ms

LOG from webpack.Compilation
<t> compute affected modules: 0.151791 ms
<t> finish modules: 0.667042 ms
<t> report dependency errors and warnings: 0.012416 ms
<t> optimize dependencies: 0.127792 ms
<t> create chunks: 1.275542 ms
<t> compute affected modules with chunk graph: 0.082084 ms
<t> optimize: 2.055334 ms
    0 modules hashed, 0 from cache (NaN variants per module in average)
<t> module hashing: 0.072875 ms
<t> code generation: 0.185833 ms
<t> runtime requirements.modules: 0.001291 ms
<t> runtime requirements.chunks: 0.108834 ms
<t> runtime requirements.entries: 0.398083 ms
<t> runtime requirements: 0.682208 ms
<t> hashing: initialize hash: 0.024625 ms
<t> hashing: hash errors: 0.005208 ms
<t> hashing: sort chunks: 0.045667 ms
<t> hashing: hash runtime modules: 0.0345 ms
<t> hashing: hash chunks: 1.049667 ms
<t> hashing: hash digest: 0.0395 ms
<t> hashing: process full hash modules: 0.004167 ms
<t> hashing: 1.557125 ms
<t> record hash: 0.020208 ms
<t> module assets: 0.057334 ms
<t> create chunk assets: 2.298542 ms
<t> process assets: 0.139 ms

LOG from webpack.ResolverCachePlugin
    50% really resolved (1 real resolves with 0 cached but invalid, 1 cached valid, 0 concurrent)

LOG from webpack.FlagDependencyExportsPlugin
<t> restore cached provided exports: 0.219125 ms
<t> figure out provided exports: 0.016417 ms
    NaN% of exports of modules have been determined (0 no declared exports, 0 not cached, 0 flagged uncacheable, 0 from cache, 0 from mem cache, 0 additional calculations due to dependencies)
<t> store provided exports into cache: 0.016209 ms

LOG from webpack.SideEffectsFlagPlugin
<t> update dependencies: 0.001625 ms

LOG from webpack.buildChunkGraph
    0 queue items processed (0 blocks)
    0 chunk groups connected
    0 chunk groups processed for merging (0 module sets, 0 forked, 0 + 0 modules forked, 0 + 0 modules merged into fork, 0 resulting modules)
    0 chunk group info updated (0 already connected chunk groups reconnected)
<t> visitModules: 0.546167 ms
<t> connectChunkGroups: 0.040042 ms
<t> cleanup: 0.025125 ms

LOG from webpack.SplitChunksPlugin
<t> prepare: 0.037709 ms
<t> modules: 0.001166 ms
<t> queue: 0.002416 ms
<t> maxSize: 0.037167 ms

LOG from webpack.FileSystemInfo
    1 new snapshots created
    0% root snapshot uncached (0 / 1)
    0% children snapshot uncached (0 / 0)
    0 entries tested
    File info in cache: 10 timestamps 0 hashes 0 timestamp hash combinations
    File timestamp snapshot optimization: 0% (0/2) entries shared via 0 shared snapshots (0 times referenced)
    Directory info in cache: 0 timestamps 0 hashes 0 timestamp hash combinations
    Missing items snapshot optimization: 0% (0/9) entries shared via 0 shared snapshots (0 times referenced)
    Managed items info in cache: 0 items

ERROR in main
Module not found: Error: Can't resolve './src' in '/Users/nathanhouse/Development/marketing-site'
resolve './src' in '/Users/nathanhouse/Development/marketing-site'
  using description file: /Users/nathanhouse/Development/marketing-site/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    using description file: /Users/nathanhouse/Development/marketing-site/package.json (relative path: ./src)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /Users/nathanhouse/Development/marketing-site/src is not a file
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /Users/nathanhouse/Development/marketing-site/src.js doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        /Users/nathanhouse/Development/marketing-site/src.json doesn't exist
      .wasm
        Field 'browser' doesn't contain a valid alias configuration
        /Users/nathanhouse/Development/marketing-site/src.wasm doesn't exist
      as directory
        existing directory /Users/nathanhouse/Development/marketing-site/src
          using description file: /Users/nathanhouse/Development/marketing-site/package.json (relative path: ./src)
            using path: /Users/nathanhouse/Development/marketing-site/src/index
              using description file: /Users/nathanhouse/Development/marketing-site/package.json (relative path: ./src/index)
                no extension
                  Field 'browser' doesn't contain a valid alias configuration
                  /Users/nathanhouse/Development/marketing-site/src/index doesn't exist
                .js
                  Field 'browser' doesn't contain a valid alias configuration
                  /Users/nathanhouse/Development/marketing-site/src/index.js doesn't exist
                .json
                  Field 'browser' doesn't contain a valid alias configuration
                  /Users/nathanhouse/Development/marketing-site/src/index.json doesn't exist
                .wasm
                  Field 'browser' doesn't contain a valid alias configuration
                  /Users/nathanhouse/Development/marketing-site/src/index.wasm doesn't exist
ModuleNotFoundError: Module not found: Error: Can't resolve './src' in '/Users/nathanhouse/Development/marketing-site'
    at /Users/nathanhouse/Development/marketing-site/node_modules/webpack/lib/Compilation.js:2094:28
    at /Users/nathanhouse/Development/marketing-site/node_modules/webpack/lib/NormalModuleFactory.js:895:13
    at eval (eval at create (/Users/nathanhouse/Development/marketing-site/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at /Users/nathanhouse/Development/marketing-site/node_modules/webpack/lib/NormalModuleFactory.js:332:22
    at eval (eval at create (/Users/nathanhouse/Development/marketing-site/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at /Users/nathanhouse/Development/marketing-site/node_modules/webpack/lib/NormalModuleFactory.js:509:22
    at /Users/nathanhouse/Development/marketing-site/node_modules/webpack/lib/NormalModuleFactory.js:151:11
    at /Users/nathanhouse/Development/marketing-site/node_modules/webpack/lib/NormalModuleFactory.js:767:25
    at /Users/nathanhouse/Development/marketing-site/node_modules/webpack/lib/NormalModuleFactory.js:979:8
    at /Users/nathanhouse/Development/marketing-site/node_modules/webpack/lib/NormalModuleFactory.js:1109:5

2024-04-17 11:41:30: webpack 5.91.0 compiled with 1 error in 34 ms (6400485c20b09f7d7a3d)
✨  Done in 0.95s.

任何帮助表示赞赏。谢谢!

webpack config webpack-5
1个回答
0
投票

嗯,我觉得很愚蠢,但也许这个问题/答案会帮助其他人犯我的愚蠢错误。

我的

module.exports
数组中的第二个对象(即带有
stats
属性)被视为第二个入口点。这个入口点(缺少
entry
属性,使得 webpack 使用其默认值 -
/src/index.js
- 不存在)。

我应该将

stats
属性放置在我的初始配置对象中,如下所示:

module.exports = [
    {
      mode: 'development',
      entry: {
        foo: './src/foo.js',
      },
      stats: 'verbose',
    },
];
© www.soinside.com 2019 - 2024. All rights reserved.