web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.81k stars 566 forks source link

[Bug]: error is thrown when a value of undefined is encountered where loader is expected #8238

Closed kubijo closed 1 week ago

kubijo commented 2 weeks ago

System Info

System:
    OS: Linux 6.11 Ubuntu 24.10 24.10 (Oracular Oriole)
    CPU: (32) x64 AMD Ryzen 9 7950X 16-Core Processor
    Memory: 41.08 GB / 60.88 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
Binaries:
    Node: 22.8.0 - ~/.volta/tools/image/node/22.8.0/bin/node
    Yarn: 4.5.1 - ~/.volta/tools/image/yarn/4.5.0/bin/yarn
    npm: 10.8.2 - ~/.volta/tools/image/node/22.8.0/bin/npm

Details

The following error is thrown when a value of undefined is encountered where loader is expected. No validation error was ever thrown even though the docs mention that a strict validation is enabled by default.

Please note that I know about incompatibility with Yarn's PNP algorithm, that is not the point of this report. The point is that the config consuming code should either filter out nil values or the validation code should shout at the user that they are supplying something fishy.

I had to go deep into the consuming code to add log-points and find out where I made a mistake (in my case, it was a forgotten reference to a loader object that I removed).

$ yarn run rspack build --config config.mjs

TypeError: Cannot read properties of undefined (reading 'type')
    at .yarn/__virtual__/@rspack-core-virtual-f10b7c4cd3/0/cache/@rspack-core-npm-1.0.14-374d04781a-3743c2dd9e.zip/node_modules/@rspack/core/dist/index.js:11275:15
    at Array.map (<anonymous>)
    at getRawModuleRule (.yarn/__virtual__/@rspack-core-virtual-f10b7c4cd3/0/cache/@rspack-core-npm-1.0.14-374d04781a-3743c2dd9e.zip/node_modules/@rspack/core/dist/index.js:11270:36)
    at .yarn/__virtual__/@rspack-core-virtual-f10b7c4cd3/0/cache/@rspack-core-npm-1.0.14-374d04781a-3743c2dd9e.zip/node_modules/@rspack/core/dist/index.js:11175:22
    at Array.map (<anonymous>)
    at getRawModule (.yarn/__virtual__/@rspack-core-virtual-f10b7c4cd3/0/cache/@rspack-core-npm-1.0.14-374d04781a-3743c2dd9e.zip/node_modules/@rspack/core/dist/index.js:11174:25)
    at getRawOptions (.yarn/__virtual__/@rspack-core-virtual-f10b7c4cd3/0/cache/@rspack-core-npm-1.0.14-374d04781a-3743c2dd9e.zip/node_modules/@rspack/core/dist/index.js:10975:13)
    at #getInstance (.yarn/__virtual__/@rspack-core-virtual-f10b7c4cd3/0/cache/@rspack-core-npm-1.0.14-374d04781a-3743c2dd9e.zip/node_modules/@rspack/core/dist/index.js:17435:24)
    at #build (.yarn/__virtual__/@rspack-core-virtual-f10b7c4cd3/0/cache/@rspack-core-npm-1.0.14-374d04781a-3743c2dd9e.zip/node_modules/@rspack/core/dist/index.js:17351:22)
    at .yarn/__virtual__/@rspack-core-virtual-f10b7c4cd3/0/cache/@rspack-core-npm-1.0.14-374d04781a-3743c2dd9e.zip/node_modules/@rspack/core/dist/index.js:17323:18

Reproduce link

No response

Reproduce Steps

Provide a config that includes an undefined value in module.rules array and run a build.

github-actions[bot] commented 2 weeks ago

Hello @kubijo, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.

kubijo commented 2 weeks ago

Run the build script here https://github.com/kubijo/rspack-loader-undefined/commit/c87722ae72a0faac49b113c417a2da7238f31d4f