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

fix(create-vite): update tsconfig with moduleDetection force #17468

Merged
merged 2 commits into from
Jun 18, 2024
Merged

fix(create-vite): update tsconfig with moduleDetection force #17468

merged 2 commits into from
Jun 18, 2024

Conversation

t-cc
Copy link
Contributor

@t-cc t-cc commented Jun 13, 2024

Description

fix #17443

Problem solved:

With the current configuration, the application may compile successfully but fail at runtime.

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.

Notes:

I was only able to reproduce this with the react and react templates.

Copy link

stackblitz bot commented Jun 13, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@bluwy
Copy link
Member

bluwy commented Jun 14, 2024

Is there a reason to only apply to the react and preact templates? Should it be applied to all tsconfigs that has isolatedModules: true?

@t-cc
Copy link
Contributor Author

t-cc commented Jun 14, 2024

Is there a reason to only apply to the react and preact templates? Should it be applied to all tsconfigs that has isolatedModules: true?

I was able to reproduce the error just react and preact (actually the absence of error). For example, with the vite template it fails at compile time without updating the typescript configuration.
https://stackblitz.com/edit/vitejs-vite-eygbwq?file=src%2Fcomponents%2Fconstants.ts,src%2Fcomponents%2FHelloWorld.vue&terminal=dev

Also I only have experience with react and preact... perhaps someone with experience in these frameworks can take care of the updates.

@bluwy
Copy link
Member

bluwy commented Jun 17, 2024

I think we should update it for the rest of the templates. It's not related to frameworks specifically. If you use MY_CONST in another .ts file for example, you can see that there's no errors either.

@t-cc
Copy link
Contributor Author

t-cc commented Jun 17, 2024

I think we should update it for the rest of the templates. It's not related to frameworks specifically. If you use MY_CONST in another .ts file for example, you can see that there's no errors either.

Yes, you are right: demo

@t-cc t-cc changed the title fix: update tsconfig in react and preact templates (fix: #17443) fix: update tsconfig in new project templates (fix: #17443) Jun 17, 2024
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bluwy bluwy changed the title fix: update tsconfig in new project templates (fix: #17443) fix(create-vite): update tsconfig with moduleDetection true Jun 18, 2024
@patak-dev patak-dev merged commit 7b240e4 into vitejs:main Jun 18, 2024
13 checks passed
@bluwy bluwy changed the title fix(create-vite): update tsconfig with moduleDetection true fix(create-vite): update tsconfig with moduleDetection force Jun 18, 2024
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 this pull request may close these issues.

Update typescript config related with isolatedModules in new project templates
3 participants