futurGH/ts-to-jsdoc

Error ERR_UNSUPPORTED_DIR_IMPORT: Directory import x is not supported resolving ES modules

Closed this issue · 1 comments

milahu commented

typescript input

import { SomeThing } from './some-dir';

actual javascript output: in ESM, this throws ERR_UNSUPPORTED_DIR_IMPORT

import { SomeThing } from './some-dir';

expected javascript output: resolve directory import to file import

import { SomeThing } from './some-dir/index.js';

in commonjs, the directory import would work

const { SomeThing } = require ('./some-dir');

ideally, ts-to-jsdoc would support converting an input directory, so it can resolve file paths

related issues

possible solutions

  • resolveFullPaths option of tsc-alias
  • add { module: "nodenext" } to compilerOptions to generate ESM javascript, then typescript requires file import and throws error TS2834: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.

Not planning on touching imports — I think I'm going to take the same stance as TS and say your imports in TS should be written the way you want them to appear in the output JS.