nxext / nx-extensions

Nx Extension for StencilJs, SvelteJS, SolidJS, Ionic and VueJs
MIT License
451 stars 100 forks source link

Vite: Vue single file component imports cause error during build and import.meta.env #995

Closed gionkunz closed 11 months ago

gionkunz commented 11 months ago

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: https://github.com/nrwl/nx/commit/b953565bc2bf9a5a6c592fee5eab9de29fe08a47#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.

image

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

Expected behavior The build should complete without any errors.