Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createRequire not detected when imported with node: prefix #16724

Closed
tripodsan opened this issue Feb 14, 2023 · 5 comments · Fixed by #16904
Closed

createRequire not detected when imported with node: prefix #16724

tripodsan opened this issue Feb 14, 2023 · 5 comments · Fixed by #16904

Comments

@tripodsan
Copy link

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

@alexander-akait
Copy link
Member

@tripodsan Sorry for delay, is your target node? Can you show me your resolver value?

@tripodsan
Copy link
Author

@alexander-akait
Copy link
Member

Yeah, bug...

@alexander-akait
Copy link
Member

I think due #14166 😄 I will look can we fix it, because it is easy to catch due node: prefix

@alexander-akait
Copy link
Member

Fix - #16904

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants