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

[Bug]: isolatedModules is not a replacement of transpileOnly #3930

Closed
unional opened this issue Dec 11, 2022 · 3 comments
Closed

[Bug]: isolatedModules is not a replacement of transpileOnly #3930

unional opened this issue Dec 11, 2022 · 3 comments
Labels
Not An Issue Not ts-jest issue

Comments

@unional
Copy link

unional commented Dec 11, 2022

Version

29.0.3

Steps to reproduce

Don't have a minimal repro, as this is about how the flag works.

You can see a test failure here:
https://github.com/justland/just-web/actions/runs/3668482089/jobs/6201650192

@just-web/events:coverage:     SyntaxError: The requested module '@unional/events-plus' does not provide an export named 'JustEventDuo'

Basically in that code, I have this line:

export { justEvent, JustEventDuo, JustEventEmpty, JustEventUno } from '@unional/events-plus'

If I add isolatedModules to tsconfig.json, I'll get this error from tsc:

ts/index.ts:5:35 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.

5 export { justEvent, JustEventDuo, JustEventEmpty, JustEventUno } from '@unional/events-plus'

That means isolatedModules should not be used as a replacement of transpileOnly, which was removed a while back.

Expected behavior

The test should run.

Actual behavior

Failed as above

Debug log

no log needed

Additional context

IMO we should re-introduce transpileOnly setting.

Environment

System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
  Binaries:
    Node: 18.7.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.15.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^29.3.1 => 29.3.1
@unional unional changed the title [Bug]: isolatedModules is not the same as skip type check [Bug]: isolatedModules is not the same as transpileOnly Dec 11, 2022
@unional unional changed the title [Bug]: isolatedModules is not the same as transpileOnly [Bug]: isolatedModules is not a replacement of transpileOnly Dec 11, 2022
@ahnpnl
Copy link
Collaborator

ahnpnl commented Dec 11, 2022

You are mistaking between 2 isolatedModules options, see improvement issue here #3750

@ahnpnl ahnpnl closed this as completed Dec 11, 2022
@ahnpnl ahnpnl added Not An Issue Not ts-jest issue and removed Bug Report Needs Triage labels Dec 11, 2022
@unional
Copy link
Author

unional commented Dec 11, 2022

Um, but the problem is the same.
If I remove isolatedModules from ts-jest config, the test pass.
If I break the export { ... } '@unional/events-plus' line into two, with one as export type {...}, the test pass too.

So it seems to me that the ts-jest isolatedModules has the same behavior and restriction.

@unional
Copy link
Author

unional commented Dec 11, 2022

I have made this a repro: https://github.com/justland/just-web/tree/ts-jest-isolated-modules

git clone justland/just-web
git checkout ts-jest-isolated-modules
pnpm i
pnpm events test

Here is the jest.config.mjs:

/** @type {import('jest').Config} */
export default {
  displayName: 'events',
  extensionsToTreatAsEsm: ['.ts'],
  moduleNameMapper: {
    '^(\\.{1,2}/.*)\\.js$': '$1',
  },
  roots: ['<rootDir>/ts'],
  testMatch: ['**/?(*.)+(spec|test|integrate|accept|system|unit).[jt]s?(x)'],
  transform: {
    '^.+\\.m?[t]sx?$': ['ts-jest', {
      isolatedModules: true,
      useESM: true
    }],
  }
}

You will see the test fails.
If you comment out isolatedModules: true,, the test will pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not An Issue Not ts-jest issue
Projects
None yet
Development

No branches or pull requests

2 participants