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

CommonJS and ESM lack appropriate extensions #41

Open
javiertury opened this issue Jul 23, 2022 · 3 comments · May be fixed by #42
Open

CommonJS and ESM lack appropriate extensions #41

javiertury opened this issue Jul 23, 2022 · 3 comments · May be fixed by #42

Comments

@javiertury
Copy link

Using this library with vite and pre-render, produces the following error:

[vite-plugin-ssr:autoFullBuild] Named export 'Fetcher' not found. The requested module 'openapi-typescript-fetch' is a CommonJS module, which may not support all module.exports as named exports.

The reason is that both CommonJS and ESM exports are using the .js extension. If package.json#type is commonjs (default), .js can be used for CommonJS but .mjs should be used for ESM. And if package.json#type is module, .js can be used for ESM output, but .cjs should be used for CommonJS.

I think "type": "module" is better because the .js extension can be used for NodeJS modules and browsers alike, making mandatory .cjs only for CommonJS files.

@javiertury javiertury linked a pull request Jul 23, 2022 that will close this issue
@ThaDaVos
Copy link

Having the same issue - cannot use the library because it throws the above error

@cuppachino
Copy link

cuppachino commented Mar 24, 2023

I've tried fixing this in my fork. It would be great to know if it works. If someone can verify I'll open a PR. It's temporarily published on npm (scoped)

@brandonp-ais
Copy link

@cuppachino

I've tested this on my work SvelteKit TS 5.0 application and it's working perfectly.

I'd previously had to set ssr: { format: 'cjs' } in vite.config.ts because of this one issue. I no longer have to, plus it's playing nice with Typescript 5.0. Bravo!

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

Successfully merging a pull request may close this issue.

4 participants