I'm trying to generate a pure ESM package (type: "module"
) using ESM in Node.js, but the Typescript generators generate relative imports without file extensions (e.g. import * as runtime from "../runtime"
) while Node.js requires file extensions for ESM imports (import * as runtime from "../runtime.js"
)
typescript
generator already has an internal option extensionForDeno
, which is set to .ts
when platform
is deno
. I suggest renaming extensionForDeno
to importFileExtension
and making it a public option.I can try putting together a PR for this, but would like to gather some feedback about whether it's a good idea first.
Describe alternatives you've consideredIt's possible to generate a valid ESM package by setting moduleResolution: "node"
(CommonJS for internal module resolution) and module: "ESNext"
, but this will fail if we add additional dependencies to the generated package that aren't CommonJS compatible.
Instead of adding a new option importFileExtension
, derive the file extension from some other option:
platform
? If we add a new value like node-esm
. The problem is that there are several different extensions that can potentially be used (.js
, .mjs
, .tjs
etc.) and users may have different preferences.moduleResolution
with values node
and node16
inspired by TypeScript?RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4