Skip to content

importing and exporting an interface fails for type module in package.json and ESXXXX module in tsconfig.json #272

@ghost

Description

Bug description

I tried tsx against a codebase where an interface is imported by a module, then re-exported. Basically it fails with:

npm start

> start
> npx tsx index.ts

~/source/tsx-repro/index.ts:1
import { Interf } from './interf.js';
         ^

SyntaxError: The requested module './interf.js' does not provide an export named 'Interf'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

See linked gist with the minimal context to reproduce this issue.

This doesn't happen with ts-node in ESM mode nor with esbuild. Basically, I piped the esbuild's STDOUT to node's STDIN and the whole codebase runs as expected. So, this behaviour is particular to tsx.

Basically, anything from ES2015 to ESNext compilerOptions module in tsconfig.json and package.json "type": "module" triggers this failure when importing and exporting an interface. It does not happen if it imports and exports a function for example.

Reproduction

https://gist.github.com/stefanrusu-loctax/8e02e07bc18d00a29c33b045d93a15a9

Environment

System:
    OS: macOS 12.6.7
    CPU: (8) arm64 Apple M1 Pro
    Memory: 91.78 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nodenv/versions/18.16.0/bin/node
    npm: 9.5.1 - ~/.nodenv/versions/18.16.0/bin/npm
    pnpm: 7.32.2 - ~/.nodenv/versions/18.16.0/bin/pnpm
  npmPackages:
    tsx: ^3.12.7 => 3.12.7

Can you work on a fix?

  • I’m interested in opening a pull request to address this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions