Skip to content

isolatedModules option is not work in ^5.0.0 version #53683

Closed

Description

@winterlood

Bug Report

🔎 Search Terms

isolatedModules

🕗 Version & Regression Information

This changed between versions 4.9.5 and 5.0.3

⏯ Playground Link

https://www.typescriptlang.org/play?isolatedModules=true#code/PTAEEsGcHsBsEMAuBTAJgWWqgrrZlRoAHRcaAO1EmUVAHJEAnbZOgKBFHnNVHOlDIAHkWiNaYiAFtR40AGtkATwDuY1BzAAjbLW5LBjRpP56iRZPEabQASQBmoJdGygAxgAtuAc2ShEHn4AbsiMkGSUiAIALAB0AJyxAKwANP6BkYGGxoygKuCwsFzmlrkqyIVsbG4UkLQodaAAvPQNiHQA3FX22ORupBSg9uQAFACUoADeAL5AA

💻 Code

tsconfig.json

{
  "compilerOptions": {
    "isolatedModules": true
  }
}

index.ts

const a = 1;

isolatedModules option set 'true'
and this code has no export or import keyword
but any error not appear

🙁 Actual behavior

it seems in 4.9.5 isolatedModules option work
but in 5.0.3 isolatedModules option not work

🙂 Expected behavior

I think the error should occur in 5.0.3, just like 4.9.5

Activity

  1. added
    Working as Intended
    and removed
    Bug
    on Apr 6, 2023
  2. andrewbranch commented on Apr 6, 2023

    @andrewbranch
    Member

    Scripts are no longer errors in isolatedModules unless they use global namespace declarations, which is the only kind of construct that is not safe to single-file transpile. See the motivating issue #46295, design discussion in #51813, and implementation at cf5c284 as part of #52203.

  3. fatcerberus commented on Apr 6, 2023

    @fatcerberus

    Andrew Branch (@andrewbranch) Somewhat related, is there a way to get TS to treat all files as modules regardless of whether they contain imports/exports or not? Or does verbatimModuleSyntax already do that?

  4. andrewbranch commented on Apr 6, 2023

    @andrewbranch
    Member

    --moduleDetection force

  5. typescript-bot commented on Apr 9, 2023

    @typescript-bot
    Contributor

    This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  6. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as Intended

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions