-
-
Notifications
You must be signed in to change notification settings - Fork 476
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
[ERR_REQUIRE_ESM] with openapi-fetch
#1102
Comments
Thanks for submitting this, and for raising a PR!
Why would a client be built in legacy CommonJS any more? That’s a deprecated module system I’d rather not support. Vite, esbuild, webpack 5, and turbopack have all since moved onto ESM. Browsers support ESM natively now (you don’t even need to bundle this library!) and Node supports ESM natively now; why should this library support legacy systems? |
It's totally fair - And it might very well just my usecase that fails to consume it. I still need to bundle our node package as I still think there's some value in using a tool like |
I understand. And appreciate the effort you took in bundling using that! I will evaluate it and kick the tires on it. For additional context, this library was originally only shipping CJS, and then CJS + ESM for a while, but we had issues piling up on both CJS and ESM where fixing one issue would break the other (more typing issues than runtime code, but don’t discount runtime code, either—it’s technically separate code that has to be tested too!). And as you probably know, TypeScript itself has horrible support for packaging multi-target builds (for example there’s no option to output Anyways, that was a long way to say I’ll evaluate tsup and see if it wouldn’t regress some interop issues users were having, and appreciate the work on this! |
Sounds good. Might also be worth to expose the exports and types field in package.json, just to help tools pick out the right files. |
Oh if only it were that easy! 😅 |
Nothings easy in the world of node modules |
Jest, React Native, Typescript, webpack, open telemetry - they all might work on their own with the right config, but all together? Forget it. Don't let this module be the thing that forces a decision on module systems. |
https://publint.dev/openapi-fetch@0.2.0 I think the exports needs to be added. |
This would be incredibly helpful, for what it's worth. I'm building a Typescript API client that must be imported by a legacy CommonJS project. Unfortunately, I can't get creative with dynamic imports, either. +1 to this thread, if possible! 🙂 |
I found an interim workaround for my use case: This allows me to bundle my Typescript NPM package with // tsup.config.ts
import { defineConfig } from 'tsup';
export default defineConfig({
entry: ['path/to/your/entry/file.ts'],
format: ['cjs', 'esm'],
noExternal: ['openapi-fetch'],
dts: true,
clean: true,
platform: 'node',
}); The Run add the following to your "type": "module",
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
}, Run |
Description
The
openapi-fetch
currently exports aindex.js
and (.index.min.js
) file, which might work fine if run in atype: 'module'
environment.However, this is something that will be bundled for the browser environment, which leads to the joy of bundling, and could also be bundled for CommonJS for the client.
Exporting both a CommonJS and ESM file, and having them indexed correctly in the
package.json
should help with this.A package like tsup should improve it. I think a simple setup like this should be enough.
Error message
Checklist
The text was updated successfully, but these errors were encountered: