OpenAPITools / OpenAPITools/openapi-generator

Using ECMAScript Modules: How to create imports with explicit file extensions?

Open
#21,479 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

I am generating a client using the openapi-generator.

The problem is that the project I want to use the generated code in requires imports with an explicit file extension (ECMAScript Modules). So, instead of

/* tslint:disable */
/* eslint-disable */
export * from './runtime';
export * from './apis/index';
export * from './models/index';

which will result in

TS2835: Relative import paths need explicit file extensions in ECMAScript imports when --moduleResolution is node16 or nodenext. Did you mean ./models/index.js?

I need the generator to create

/* tslint:disable */
/* eslint-disable */
export * from './runtime.js';
export * from './apis/index.js';
export * from './models/index.js';

Is there a way to configure the generator s.t. this works? I'd like to avoid a fix-imports.ts script here..

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the TypeScript generator templates that produce the shown runtime, API, and model exports, then check the available configuration options for import paths. Generate a client using Node16 or NodeNext module resolution and verify that relative imports use explicit .js extensions without requiring a separate fix-imports.ts script.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.