Open exploids opened 1 year ago
Thanks for submitting an issue. I am unfortunately not really familiar with ECMAScript modules as I am primarily working only with typescript. Could you elaborate a bit more on what you need?
The generated files are typescript files are you sure you expect the file extension to be .js
and not .ts
? I mean, is it actually possible to have interfaces or typescript types in javascript files?
I think the easiest way to solve this would be to add a flag that would affect the import statements.
I'm working purely in TypeScript as well, transpiling the TypeScript sources to JavaScript for execution with Node.js. I'm no expert on this topic, but here's how I understand it:
Recent versions of Node.js support the usage of ECMAScript Modules (that article also explains a bit how to use them with TypeScript) instead of CommonJS modules. The ESM system uses an import
/export
syntax that requires file extensions for relative paths (e.g. import { Thing } from './thing.js'
would be valid, import { Thing } from './thing'
would be invalid).
Newer versions of TypeScript are able to emit ESM by setting module and moduleResolution to node16
in the tsconfig.json. But in order or this to work correctly, the TypeScript sources also need to use valid ESM imports/exports, so relative paths in imports also need file extensions.
The generated files are typescript files are you sure you expect the file extension to be .js and not .ts? I mean, is it actually possible to have interfaces or typescript types in javascript files?
For some reason, when importing from other TypeScript files (e.g. thing.ts) with ESM, the import still requires a .js extension (e.g. import { Thing } from './thing.js'
).
I think the easiest way to solve this would be to add a flag that would affect the import statements.
Yeah, I think so too.
Okay, thanks for elaborating, I can try to make an update at some point when I have the time. I do need to do some more refactoring to make this easy to implement.
The imports/exports generated by this tool are not compatible with ECMAScript Modules out of the box, as they are missing the mandatory file extension. It would be useful to be able to configure this behaviour manually or have the tool resolve the current module system through the tsconfig.json file(s).
Expected output
Actual output
Causes the following error:
Alternatively, an option to generate all types into a single file without the need for imports/exports could resolve this issue.