-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[2.3.0+] TypeError: Unknown file extension ".json" for /...package.json #3481
Comments
Either change your file extension to .js, configure Node to use Our assumption is that if you are using .mjs, you are doing so because you want your code to follow Node 13+ ES module semantics, which will now be enforced by loading your config as a Node ES module. |
Here is another way to fix this: https://nodejs.org/api/esm.html#esm_commonjs_json_and_native_modules |
Can you speak a little more about that assumption and how that changed from 2.2.0? I guessed that this was a change to better conform to standards but I am confused about why it worked and then stopped? I am using node 14 in 2.2 and it is working fine. So I am just confused about how the assumptions changed. Is there a release note that might help me better understand the motive better? |
I tried using the code in my project (more advanced than the example I gave)...
But again with no code changes I now get...
Which again works fine when I downgrade to 2.2 |
Seems to be with all the plugins I commented out lint and now I get...
|
It is all explained in the documentation I linked. Prior to 2.3, all configs were transpiled to CJS before they were executed, now they are not if you are using Node 13+. Before 2.3, we did not try to replicate Node ESM semantics also because they were somewhat unstable at that time. Most plugins, including terser, are only available as CJS. If a Node ES module imports a CJS module, it will only receive a default export. In case of e.g. terser, you could
|
When I remove both plugins it does seem to work. |
By the way, it is actually not true what I said earlier that those plugins are only available as CJS, they are just not configured to provide an ES module when they are imported from a Node ES module. They would need to use conditional exports to make that work, just like Rollup itself does it now. |
Right and just for the record the working example was...
Just cause the dependency was wrong and didn't want to confuse people. Or am I wrong and I should be using the terser library directly? |
No, you are right, it should of course import from the plugin 🙄 |
In the config files, you can always do: import { readFileSync } from "fs"; |
Expected Behavior
Pre-2.3.0 (IE 2.2.0) I could just run
rollup -c rollup.config.mjs
and everything would work.Actual Behavior
After 2.3.0 I get...
Work Around
Explicitly use version 2.2.0 in my package.json
The text was updated successfully, but these errors were encountered: