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
Require.cache causes errors #4616
Comments
Needs to be added here: parcel/packages/shared/scope-hoisting/src/hoist.js Lines 266 to 280 in 9f71164
|
A quick trial shows this working for me 👍 It reinstates the parcel v1 shim behaviour. Is there somewhere I can add tests? if (t.matchesPattern(path.node, 'module.id')) {
path.replaceWith(t.stringLiteral(asset.id));
}
if (t.matchesPattern(path.node, 'module.hot')) {
path.replaceWith(t.identifier('null'));
}
if (t.matchesPattern(path.node, 'module.require') && !asset.env.isNode()) {
path.replaceWith(t.identifier('null'));
}
+ if (t.matchesPattern(path.node, 'require.cache') && !asset.env.isNode()) {
+ path.replaceWith(t.identifier('{}'));
+ }
if (t.matchesPattern(path.node, 'module.bundle')) {
path.replaceWith(t.identifier('parcelRequire'));
} |
The fixture would be similar to https://github.com/parcel-bundler/parcel/tree/v2/packages/core/integration-tests/test/integration/scope-hoisting/commonjs/require-resolve (also in the |
Great, thank you! I aim to open a PR this week. |
This issue should be closed fixed by #4621 |
@navaru it did not get fixed, the PR has been closed not merged. |
🐛 bug report
Parcel does not transform
require.cache
when bundling, which cause an error when running the bundled file.🎛 Configuration (.babelrc, package.json, cli command)
The bundle command is
parcel build index.js --target esm --no-minify
🤔 Expected Behavior
The bundled output should run without error.
😯 Current Behavior
Running the bundled file will cause the following error:
💁 Possible Solution
Parcel 1 created a shim for
require.cache
. See this earlier issue and PR:In the v2 branch there is a skipped test for the shim.
🔦 Context
I want to package
node_modules
dependencies into my bundle. Some of these dependencies make use ofrequire.cache
.💻 Code Sample
Repro here: https://github.com/m-allanson/parcel-require-repro
The
dist
directory is committed too.Example code that will cause the error:
🌍 Your Environment
The text was updated successfully, but these errors were encountered: