You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run npm run dev, you will see graphql version is displayed by app.vue, meaning code imports from the global graphql package.
Run nuxi typecheck, you will see that it doesn't type check, as types import from the local graphql directory:
❯ nuxi typecheck
Nuxi 3.5.1
app.vue:2:8 - error TS1192: Module '"/home/projects/nuxt-starter-gjecyr/graphql/index"' has no default export.
2 import graphql from 'graphql';
~~~~~~~
Found 1 error in app.vue:2
Describe the bug
Adding a directory under project root shadows the global package with the same name when type checking (not in runtime).
In the reproduction, I added graphql/index.ts under Nuxt project root. That breaks import ... from "graphql" for type checking. What is worse, type imports break inside other libraries such as @urql/vue or villus which is hard to diagnose.
Additional context
This is caused by .nuxt/tsconfig.json having baseUrl pointing to project root. I believe that serves no real purpose and is a time bomb for types shadowing. As I gathered, it's only needed for setting up non-relative path aliases such as "#imports": [".nuxt/imports"] which is simple to avoid (the majority of the generated aliases are already relative).
I tried removing baseUrl and converting remaining non-relative path aliases to relative ("@/*": ["../*"], "#imports": ["./imports"], etc.) and everything seemed to work fine.
Logs
No response
The text was updated successfully, but these errors were encountered:
Environment
Reproduction
https://stackblitz.com/edit/nuxt-starter-gjecyr?file=app.vue,graphql%2Findex.ts
Run
npm run dev
, you will see graphql version is displayed byapp.vue
, meaning code imports from the globalgraphql
package.Run
nuxi typecheck
, you will see that it doesn't type check, as types import from the localgraphql
directory:Describe the bug
Adding a directory under project root shadows the global package with the same name when type checking (not in runtime).
In the reproduction, I added
graphql/index.ts
under Nuxt project root. That breaksimport ... from "graphql"
for type checking. What is worse, type imports break inside other libraries such as@urql/vue
orvillus
which is hard to diagnose.Additional context
This is caused by
.nuxt/tsconfig.json
havingbaseUrl
pointing to project root. I believe that serves no real purpose and is a time bomb for types shadowing. As I gathered, it's only needed for setting up non-relative path aliases such as"#imports": [".nuxt/imports"]
which is simple to avoid (the majority of the generated aliases are already relative).I tried removing
baseUrl
and converting remaining non-relative path aliases to relative ("@/*": ["../*"]
,"#imports": ["./imports"]
, etc.) and everything seemed to work fine.Logs
No response
The text was updated successfully, but these errors were encountered: