Skip to content

Cannot use with ESM module #37

@slhck

Description

@slhck

I have a TypeScript project that I'm trying to convert to use ESM via the following options:

{
  "compilerOptions": {
    "target": "es6",
    "module": "esnext",
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
   // ...
}

The code I used to have was like this:

import spawnAsync, { SpawnOptions, SpawnPromise, SpawnResult } from '@expo/spawn-async';

// ...

spawnAsync();

I am trying to run the project with ts-node (ts-node --esm src/index.ts), but now, I get this error on the call:

  Type 'typeof import("./node_modules/@expo/spawn-async/build/spawnAsync")' has no call signatures.

18   const proc = spawnAsync(cmd, args, opts);
                  ~~~~~~~~~~

    at createTSError (./node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (./node_modules/ts-node/src/index.ts:863:19)
    at getOutput (./node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (./node_modules/ts-node/src/index.ts:1433:41)
    at transformSource (./node_modules/ts-node/src/esm.ts:400:37)
    at ./node_modules/ts-node/src/esm.ts:278:53
    at async addShortCircuitFlag (./node_modules/ts-node/src/esm.ts:409:15)
    at async ESMLoader.load (node:internal/modules/esm/loader:303:20)
    at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:230:47) {
  diagnosticCodes: [ 2349 ]
}

Notably, no other dependency I am using (out of 80-something) has this issue. I wonder if the exports of this project could be made in such a way that they work with both CommonJS and ESM?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions