Skip to content

TypeError: RegExpPrototypeExec is not a function when using esm loader #1526

@SimonSiefke

Description

@SimonSiefke

Search Terms

RegExpPrototypeExec, ESM

Expected Behavior

It shows no error

Actual Behavior

It shows an error:

(node:9814) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
TypeError: RegExpPrototypeExec is not a function
    at defaultGetFormat (/tmp/tsnode-bug/node_modules/ts-node/dist-raw/node-esm-default-get-format.js:50:24)
    at defer (/tmp/tsnode-bug/node_modules/ts-node/src/esm.ts:170:7)
    at /tmp/tsnode-bug/node_modules/ts-node/src/esm.ts:175:14
    at Generator.next (<anonymous>)
    at /tmp/tsnode-bug/node_modules/ts-node/dist/esm.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/tmp/tsnode-bug/node_modules/ts-node/dist/esm.js:4:12)
    at getFormat (/tmp/tsnode-bug/node_modules/ts-node/dist/esm.js:108:16)
    at /tmp/tsnode-bug/node_modules/ts-node/src/esm.ts:127:14
    at Generator.next (<anonymous>)

Steps to reproduce the problem

const supportsESM = async () => {
  try {
    // @ts-ignore
    await import("data:text/javascript,");
    return true;
  } catch (error) {
    console.error(error);
  }
  return false;
};

supportsESM();

Using node --loader ts-node/esm src/index.ts results in the error above

Minimal reproduction

See https://github.com/SimonSiefke/ts-node-esm-bug

Specifications

ts-node v10.3.1
node v17.0.1
compiler v4.5.0-beta

  • ts-node version:
  • node version:
  • TypeScript version:
  • tsconfig.json, if you're using one:
{
  "compilerOptions": {
    "outDir": "dist",
    "target": "ESNext",
    "module": "ESNext",
    "lib": ["ESNext"]
  },
  "include": ["src"]
}

  • Operating system and version:
    Ubuntu 21.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions