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

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

Closed
SimonSiefke opened this issue Oct 21, 2021 · 3 comments · Fixed by #1529
Closed

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

SimonSiefke opened this issue Oct 21, 2021 · 3 comments · Fixed by #1529
Milestone

Comments

@SimonSiefke
Copy link

@SimonSiefke SimonSiefke commented Oct 21, 2021

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
@cspotcode
Copy link
Collaborator

@cspotcode cspotcode commented Oct 21, 2021

Thanks for the detailed reproduction. This looks like a missing primordial in this file: https://github.com/TypeStrong/ts-node/blob/main/dist-raw/node-primordials.js

It is only used for data: URIs which is probably why our tests didn't catch it.

if (parsed.protocol === 'data:') {
const [ , mime ] = RegExpPrototypeExec(

Thankfully, should be a quick fix, and we can add a data URI test while we're at it.

@cspotcode
Copy link
Collaborator

@cspotcode cspotcode commented Oct 22, 2021

@SimonSiefke this has been published in 10.4.0; please let us know if it fixes the problem for you.

https://github.com/TypeStrong/ts-node/releases/tag/v10.4.0

@SimonSiefke
Copy link
Author

@SimonSiefke SimonSiefke commented Oct 22, 2021

Works great. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants