-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Closed
Description
Bug report
What is the current behavior?
using createRequire isn't detected when imported with node: prefix. i.e. the imported module is not resolved.
If the current behavior is a bug, please provide the steps to reproduce.
A dependency (@adobe/fetch) uses createRequire to import the package.json:
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const pkg = require('../../package.json');the generated bundle contains:
const require = (0,node_module__WEBPACK_IMPORTED_MODULE_0__.createRequire)("file:///..../node_modules/@adobe/fetch/src/core/request.js");
const pkg = require('../../package.json');which doesn't work, since the package.json will not be available once using the bundle.
when we change the import and remove the node: prefix:
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const pkg = require('../../package.json');then bundle package.json is resolved and included in the bundle:
const require = /* createRequire() */ undefined;
const pkg = __webpack_require__(/*! ../../package.json */ "./node_modules/@adobe/fetch/package.json");What is the expected behavior?
createRequire should be detected even if it's imported via the node:module prefix.
Other relevant information:
webpack version: 5.75.0
Node.js version: 18.13.0
Operating System: macOS
Reactions are currently unavailable