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

Type stripping with VM modules #56550

Closed
slagiewka opened this issue Jan 10, 2025 · 2 comments
Closed

Type stripping with VM modules #56550

slagiewka opened this issue Jan 10, 2025 · 2 comments
Labels
invalid Issues and PRs that are invalid. strip-types Issues or PRs related to strip-types support vm Issues and PRs related to the vm subsystem.

Comments

@slagiewka
Copy link

Version

v23.6.0

Platform

Darwin mbp.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

  1. Get jest
  2. Configure jest to run ESM
export default {
  transform: {},
  extensionsToTreatAsEsm: ['.ts'],
}
  1. Write a simple type annotation inside example.test.ts.
  2. Run node --experimental-vm-modules node_modules/jest/bin/jest.js

Reproduction repository: https://github.com/slagiewka/jest_node_ts

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

Type stripping works with Jest and ESM (via VM modules).

What do you see instead?

❯ node --experimental-vm-modules node_modules/jest/bin/jest.js
 FAIL  ./example.test.ts
  ● Test suite failed to run

    SyntaxError: Unexpected token ':'

      at Runtime.loadEsmModule (node_modules/jest-runtime/build/index.js:516:20

The corresponding line in source code: https://github.com/jestjs/jest/blob/611d1a4ba0008d67b5dcda485177f0813b2b573e/packages/jest-runtime/src/index.ts#L501

Additional information

I'm not sure if this is something that is an issue on node or Jest side. I'll be happy to report it to Jest if there's nothing that node can do here.

@slagiewka
Copy link
Author

Looking at the source of issue, this is the minimal reproduction without importing anything external:

import { SourceTextModule } from "node:vm";

new SourceTextModule(`let foobar: string;`);

@slagiewka slagiewka changed the title Type stripping with VM modules (Jest) Type stripping with VM modules Jan 10, 2025
@joyeecheung
Copy link
Member

SourceTextModule corresponds to a SourceTextModule in the ECMAScript specification, so it's JavaScript. To strip the types, use module.stripTypeScriptTypes() to process the code first before passing it into SourceTextModule.

@joyeecheung joyeecheung closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2025
@joyeecheung joyeecheung added invalid Issues and PRs that are invalid. vm Issues and PRs related to the vm subsystem. strip-types Issues or PRs related to strip-types support labels Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Issues and PRs that are invalid. strip-types Issues or PRs related to strip-types support vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

2 participants