openapi-typescript-fetch icon indicating copy to clipboard operation
openapi-typescript-fetch copied to clipboard

CommonJS and ESM lack appropriate extensions

Open javiertury opened this issue 2 years ago • 3 comments

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 avatar Jul 23 '22 14:07 javiertury

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

ThaDaVos avatar Aug 27 '22 11:08 ThaDaVos

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)

cuppachino avatar Mar 24 '23 00:03 cuppachino

@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!

brandonp-ais avatar Mar 24 '23 01:03 brandonp-ais