-
Notifications
You must be signed in to change notification settings - Fork 145
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Environment
npx envinfo --system --npmPackages 'unplugin' --binaries --browsers
System:
OS: macOS 15.6
CPU: (10) arm64 Apple M1 Max
Memory: 393.00 MB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.15.0 - ~/.volta/tools/image/node/22.15.0/bin/node
Yarn: 4.9.1-git.20250411.hash-1908ee79f - ~/.volta/tools/image/yarn/4.9.1/bin/yarn
npm: 10.9.2 - ~/.volta/tools/image/node/22.15.0/bin/npm
pnpm: 10.11.0 - ~/.volta/bin/pnpm
Browsers:
Brave Browser: 137.1.79.126
Chrome: 139.0.7258.128
Safari: 18.6
npmPackages:
unplugin: ^2.3.6 => 2.3.6 Reproduction
# create base folder
mkdir unplugin-repro-loader-crash
cd unplugin-repro-loader-crash
# add dependencies (rspack + unplugin)
pnpm add -D unplugin @rspack/core @rspack/cli
mkdir src
# entry point - imports a .custom file
echo 'const test = require("./test.custom"); console.log(test);' > src/index.js
# dummy content
echo 'TEST STRING' > src/test.custom
# plugin for .custom files - throwing on load
cat << EOF > custom-loader.js
const { createUnplugin } = require("unplugin");
module.exports = createUnplugin(() => ({
name: "custom-plugin",
load: {
filter: {
id: /\.custom$/,
},
handler(id) {
throw id
},
},
}));
EOF
# basic configuration
cat << EOF > rspack.config.js
const { defineConfig } = require("@rspack/cli");
const CustomLoader = require("./custom-loader");
module.exports = defineConfig({
entry: "./src/index.js",
plugins: [CustomLoader.rspack()],
});
EOF
# crashes because of an unhandled promise rejection :(
pnpm rspack buildDescribe the bug
Node panics and crashes when throwing inside the load handler for rspack instead of aborting gracefully.
Additional context
Likely caused by the rspack "load" loader missing a try {} catch {} block - unlike the "transform" loader.
Logs
Running the program above results in the following crash…
node:internal/process/promises:389
new UnhandledPromiseRejection(reason);
^
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "/Users/julien.elbaz/dev/experiments/unplugin-repro-loader-crash/src/test.custom".
at throwUnhandledRejectionsMode (node:internal/process/promises:389:7)
at processPromiseRejections (node:internal/process/promises:470:17)
at process.processTicksAndRejections (node:internal/process/task_queues:96:32) {
code: 'ERR_UNHANDLED_REJECTION'
}
Node.js v20.15.1…instead of letting rspack handle the error gracefully like this:
ERROR in ./src/test.custom
× Module build failed:
╰─▶ × Error: /Users/julien.elbaz/dev/experiments/unplugin-repro-loader-crash/src/test.custom
│ at Object.load (file:///Users/julien.elbaz/dev/experiments/unplugin-repro-loader-crash/node_modules/.pnpm/unplugin@2.3.6/node_modules/unplugin/dist/rspack/loaders/load.js:22:17)
│ at /Users/julien.elbaz/dev/experiments/unplugin-repro-loader-crash/node_modules/.pnpm/@rspack+core@1.4.11/node_modules/@rspack/core/dist/index.js:3050:29
│ at node:internal/util:431:7
│ at new Promise (<anonymous>)
│ at node:internal/util:417:12
│ at isomorphoicRun (/Users/julien.elbaz/dev/experiments/unplugin-repro-loader-crash/node_modules/.pnpm/@rspack+core@1.4.11/node_modules/@rspack/core/dist/index.js:3549:244)
│ at runLoaders (/Users/julien.elbaz/dev/experiments/unplugin-repro-loader-crash/node_modules/.pnpm/@rspack+core@1.4.11/node_modules/@rspack/core/dist/index.js:3599:145)
Rspack compiled with 1 error in 71 msReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working