-
-
Notifications
You must be signed in to change notification settings - Fork 607
Open
Description
- Rollup Plugin Name: @rollup/plugin-commonjs
- Rollup Plugin Version: 28.0.6
- Rollup Version: 4.52.3
- Operating System (or Browser): macOS Sequoia 15.7
- Node Version: 20.19.1
- Link to reproduction: https://stackblitz.com/edit/rollup-repro-e7l8tnnm?file=rollup.config.js
Expected Behavior
strictRequires
with true
handle dynamically external required builtins without hoisting them.
After a npm run build
, both npm run exec:dev
and npm run exec:build
should work with same behavior and output.
Actual Behavior
Even if there is no usage of SqliteCacheStore
of nodejs/undici the node:sqlite
builtin is hoisted and eagerly loaded.
Node 20
Error [ERR_UNKNOWN_BUILTIN_MODULE]: No such built-in module: node:sqlite
at ModuleLoader.builtinStrategy (node:internal/modules/esm/translators:163:4686)
at #a (node:internal/modules/esm/loader:157:4044)
at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:157:4594) {
code: 'ERR_UNKNOWN_BUILTIN_MODULE'
}
Node 22
(node:33652) ExperimentalWarning: SQLite is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Additional Information
Both rolldown/rolldown and webpack/webpack automatically handle this by default if the target is node
. By injecting a shim for require
and using createRequire
.
Workaround
Manually use ignore
and banner
to inject the usage of createRequire
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
export default {
input: 'src/main.js',
output: {
dir: 'dist',
format: 'es',
banner: "import { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);\n"
},
external: ['node:sqlite'],
plugins: [
commonjs({ strictRequires: true, ignore: ['node:sqlite'] }),
resolve({ preferBuiltins: true }),
],
};
Metadata
Metadata
Assignees
Labels
No labels