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

Update typescript config related with isolatedModules in new project templates #17443

Closed
7 tasks done
t-cc opened this issue Jun 11, 2024 · 2 comments · Fixed by #17468
Closed
7 tasks done

Update typescript config related with isolatedModules in new project templates #17443

t-cc opened this issue Jun 11, 2024 · 2 comments · Fixed by #17468

Comments

@t-cc
Copy link
Contributor

t-cc commented Jun 11, 2024

Describe the bug

The tsconfig file needs to be updated for new typescript project templates.

With the current configuration, the application may compile successfully but fail at runtime. To fix this, we only need to add "moduleDetection": "force" in the compilerOptions.

More info here:microsoft/TypeScript#55785

Reproducible example here:https://stackblitz.com/edit/vitejs-vite-srbrdd

Reproduction

https://stackblitz.com/edit/vitejs-vite-srbrdd?file=tsconfig.json

Steps to reproduce

  1. Start a new typescript react project: https://vite.new/react-ts
  2. Add a new ts file inside the src folder (for example newfile.ts) with this content: const MY_CONST = 1
  3. Print the value of the constant inside App.tsx : {MY_CONST},

At this point, you should be able to compile (with npx tsc --noEmit) or build the app ( npm run build ) without errors, but the app fails at runtime ( npm run dev ) in the preview.

To fix this, we only need to add "moduleDetection": "force" in the compilerOptions.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1 
    vite: ^5.2.13 => 5.2.13

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Jun 11, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@bluwy
Copy link
Member

bluwy commented Jun 12, 2024

Feels a bit edge-casey but it doesn't seem like there's downsides to adding that option. Feel free to submit a PR adding that.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants