-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Support clearing Node.js cache for package.json #54924
Comments
How are you loading the files? |
I'm loading the files with I created a simple project to demonstrate it. You can simply clone it |
CC @nodejs/loaders |
I know you said it's out of scope, but I'd love to understand why adding type:module (and changing the meaning of every |
@GiladShoham please take a look at the last message. Do you think this would be a viable option for Bit? |
Yes I think it might work. |
Now that I think about it, the templates that Bit allows users to create components from can actually be developed by the community. This means we don’t have full control over these templates, and developers might configure the "type": "module" setting in the package.json instead of using file extensions. While we can document this, it’s not a foolproof solution. Identifying the cause of this issue can be quite challenging. |
What is the problem this feature will solve?
When a long-running Node.js process is active and a package.json file is modified (for example, by adding "type": "module"), Node.js does not detect this change. It continues treating the package as CommonJS, which results in an error like Unexpected token 'export' when attempting to use ES modules.
This is crucial for us at bit, where we run a background process called “bit server” that manages the local development workspace. Among its tasks is creating new web components, which initially have a package.json without "type": "module". If the component is later determined to be ESM, the package.json is updated accordingly. (Explaining why this can’t be handled differently is beyond the scope of this feature request).
What is the feature you are proposing to solve the problem?
I propose adding an API that allows clearing the cached information related to the package.json of a specific module (or optionally clearing the cache for all modules). Either option would solve the issue.
What alternatives have you considered?
Restarting the Node.js process, but this results in a poor user experience.
The text was updated successfully, but these errors were encountered: