Skip to content

Unable to import 'postprocessing' in ESM-based Node.js #409

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

Closed
donmccurdy opened this issue Sep 9, 2022 · 4 comments
Closed

Unable to import 'postprocessing' in ESM-based Node.js #409

donmccurdy opened this issue Sep 9, 2022 · 4 comments
Labels
enhancement Enhancement of existing functionality

Comments

@donmccurdy
Copy link
Member

donmccurdy commented Sep 9, 2022

I'm using Ava and Node.js to run unit tests, and postprocessing is in the dependencies of the tested code. When running the tests, Node.js hits this error:

SyntaxError: The requested module 'postprocessing' does not provide an export named 'Effect'

Of course postprocessing does export Effect, in fact. I think this comes down to nodejs/node#32137. Node.js expects that ES Modules will either (a) use "type": "module" or (b) use .mjs, if I understand this correctly. Because postprocessing currently does neither, it cannot resolve the import.

This isn't urgent for me, but I just wanted to flag the issue. I see Remove CJS bundles, change type to module on the roadmap; that would certainly solve the issue as far as I'm concerned. I believe it would be a non-breaking change to add "type": "module" now, as long as you keep the main entry and change its extension to .cjs. Example:

https://github.com/donmccurdy/KTX-Parse/blob/d7e7fefbef44642d5dbb9444a64bc055d4483ce8/package.json#L5-L14

EDIT: I'm testing with Node v18.5.0

@vanruesc
Copy link
Member

This would be a breaking change because it causes issues for React and Webpack 4 builds (#277, #312, #346, pmndrs/react-postprocessing#114).

You could import from postprocessing/module instead which exports an .mjs bundle for Ava.js testing, but that export will also be removed in v7.

@vanruesc vanruesc added the enhancement Enhancement of existing functionality label Sep 10, 2022
@donmccurdy
Copy link
Member Author

Sorry, I don't think I follow the connection with those threads — the example config from ktx-parse is what I'm proposing, and hoping might not be a breaking change. I'm not proposing that postprocessing use .mjs files. I don't mind waiting for v7 either, though. Thanks!

@vanruesc
Copy link
Member

Those threads were problems that occured after I tried changing the package type to module or the extension of the bundle to .mjs. I don't remember the exact configs I tried, but it all turned out to be a breaking change in some way or another. Maybe the configuration you propose is actually non-breaking, but I'd rather make the change in v7.

@donmccurdy
Copy link
Member Author

Makes sense, thanks! The whole cjs / mjs situation is really something. I'm glad to see more packages moving to ESM-first. Let me know if I can help here, or feel free to close the issue if this is already covered by the roadmap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of existing functionality
Projects
None yet
Development

No branches or pull requests

2 participants