Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orval generates wrong import paths in ESM-only package #1232

Open
jakubmazanec opened this issue Feb 21, 2024 · 5 comments
Open

Orval generates wrong import paths in ESM-only package #1232

jakubmazanec opened this issue Feb 21, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@jakubmazanec
Copy link

What are the steps to reproduce this issue?

Use custom Axios instance in ESM-only package (i.e. that uses type: "module" in package.json and "module": "node16", "moduleResolution": "node16" in tsconfig.json).

What happens?

Generated code that imports the custom Axios is:

import {customInstance} from './customInstance';

What were you expecting to happen?

Generated code that imports the custom Axios should be:

import {customInstance} from './customInstance.js';

Any logs, error output, etc?

TypeScript errors: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './customInstance.js'? ​typescript(2835)

What versions are you using?

Package Version: 6.25.0

@melloware melloware added the bug Something isn't working label Feb 22, 2024
@melloware
Copy link
Collaborator

Hmmm i wonder if there is a way orval can detect what ts-config you are using? I somehow doubt it.

@jakubmazanec
Copy link
Author

Maybe an option like useExtensionsInImportPaths: true would suffice? Anyway, extensions are mandatory when using ES modules, so it's not just TypeScript-related bug.

@melloware
Copy link
Collaborator

PR is welcome!

@maapteh
Copy link

maapteh commented Nov 8, 2024

@melloware the same is for allowImportingTsExtensions in tsconfig to directly run your ts with NodeJS.

Now the generated target needs to be including the extensions:

import type {
    Foo
} from './index.schemas.ts'
import { client } from '../mutator/client.ts'
import type { ErrorType } from '../mutator/client.ts'

If you can give any pointer how this would work great?

current config:

      workspace: 'src/api/',
      target: 'index.ts',
      mode: 'split',
      clean: true,
      prettier: true,
      override: {
        mutator: {
          path: '../mutator/client.ts',
          name: 'client',
        },

This generates the index.ts file with imports. Can it become an Orval config variable?

@melloware
Copy link
Collaborator

@anymaniax @soartec-lab i am not sure how this exactly would work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants