Vite: Vue single file component imports cause error during build and import.meta.env
gionkunz opened this issue · comments
Describe the bug
Since Nx 16.4.0 the @nx/vite build executor runs a TypeScript type check before the vite build. This new behaviour is turned on by default.
See: nrwl/nx@b953565#diff-25207db542ebf5643a1b5bf75c5e812f6503b1026bfc8a156b7fc82b4bb0ab43R24-R28
And: https://github.com/nrwl/nx/blob/master/packages/vite/src/executors/build/build.impl.ts#L47-L53
I think this potentially breaks a lot of projects and should have been introduced with skipTypeCheck=true
for 16.* with a warning and switched to skipTypeCheck=false
in Nx 17.
As a consequence, we need to make the generated projects compatible with a regular TS type check and therefore shim the Vue SFC within an included .d.ts file.
The second issue found in the generated default app in the router config is related to a different issue. The missing type augmentation from vite/client.d.ts
for import.meta
are not available because the types in tsconfig.app.json
override the types specified in tsconfig.json
. The best way to fix this would be to add vite/client.d.ts
to the types specified in tsconfig.app.json
or even remove the types from it completely and let it inherit from tsconfig.json
.
To Reproduce
- Use any version of Nx after 16.4.0
- Install nxext/vue
- Generate a new app with the router config turned on
- Run a build
Expected behavior
The build should complete without any errors.