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

require.cache missing #1959

Closed
jfrconley opened this issue Aug 29, 2018 · 5 comments
Closed

require.cache missing #1959

jfrconley opened this issue Aug 29, 2018 · 5 comments

Comments

@jfrconley
Copy link
Contributor

❔ Question

What properties are supposed to be available on the require object at runtime? Is it intended to fully mirror the node require?

πŸ”¦ Context

I am testing out the new "--bundle-node-modules" option, but some node_modules try to get the keys for the require cache and die.

πŸ’» Code Sample

This code will fail when bundled

Object.key(require.cache);

🌍 Your Environment

Software Version(s)
Parcel latest git
@DeMoorJasper
Copy link
Member

It has no properties, it's just a function that takes in the location of a file. Or identifier in compiled code.

If you really wanna dig into parcel internals there is a resolve property on it but that's it.

You can have a look at https://github.com/parcel-bundler/parcel/blob/master/src/builtins/prelude.js for the entire implementation of require

@jfrconley
Copy link
Contributor Author

Hmm, is there a reason that stubs for require.cache and the like couldn't be added to local require to better support bundled node modules? They wouldn't do anything, but I think it would still help compatibility

@DeMoorJasper
Copy link
Member

What's the use-case?

@jfrconley
Copy link
Contributor Author

jfrconley commented Aug 30, 2018

Preventing code like this from crashing on startup
Object.keys(require.cache)
In my case, it's buried inside of a transitive dependency.
require.cache can validly be an empty object, I think it would be a simple way to improve compatibility

@DeMoorJasper
Copy link
Member

Feel free to open up a PR or RFC

jfrconley pushed a commit to jfrconley/parcel that referenced this issue Aug 30, 2018
DeMoorJasper pushed a commit that referenced this issue Aug 30, 2018
* Added a simple stub for require.cache in prelude (#1959)
devongovett pushed a commit that referenced this issue Oct 15, 2018
* Added a simple stub for require.cache in prelude (#1959)
devongovett pushed a commit that referenced this issue Oct 15, 2018
* Added a simple stub for require.cache in prelude (#1959)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants