Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #14333
Closed
Open
Issue created Dec 27, 2022 by Administrator@rootContributor

[REQ] New typescript-generator option to set file extension for ECMAScript module resolution

Created by: danmichaelo

Is your feature request related to a problem? Please describe.

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")

Describe the solution you'd like

  • The 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.
  • The other typescript generators does not have such an option, so it may have to be added to those, if needed

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 considered

  • It'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:

    • From 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.
    • Perhaps a new option moduleResolution with values node and node16 inspired by TypeScript?
Assignee
Assign to
Time tracking