cngJo / nuxt-turborepo

NuxtJS setup based on turborepo
1 stars 0 forks source link

Figure out a way to proper support auto imports in editors #5

Closed cngJo closed 1 year ago

cngJo commented 1 year ago

Currently, when you e.g. have an server/api/hello.ts in the apps/web project, VS Code will not pick up e.g. the defineEventHandler auto import.

Also, importing from #app or #imports does not work.

Both probably because the app is not in the root-directory of the editor.

cngJo commented 1 year ago

It seems like this could be caused by our tsconfig.json not including the tsconfig form nuxt.

If this is the case, fixing this would require us to include multiple tsconfig.json files, this is currently not possible but will be with typescript 5.0 (https://github.com/microsoft/TypeScript/pull/50403)

cngJo commented 1 year ago

Tests with a dev-build from typescript (5.0.0-dev.20230220) failed. But this seems to be related to vite(-vue) and not to typescript itself.

[vite:vue] The "path" argument must be of type string. Received an instance of Array
file: /path/to/project/apps/web/src/pages/index.vue

 ERROR  The "path" argument must be of type string. Received an instance of Array                                                                                                                                                                                                             19:34:51

  at new NodeError (node:internal/errors:399:5)
  at validateString (node:internal/validators:163:11)
  at Object.isAbsolute (node:path:1161:5)
  at resolveExtends (/path/to/project/node_modules/vite/dist/node/chunks/dep-9912c491.js:13204:21)
  at parseExtends (/path/to/project/node_modules/vite/dist/node/chunks/dep-9912c491.js:13181:34)
  at parse$f (/path/to/project/node_modules/vite/dist/node/chunks/dep-9912c491.js:13127:24)
  at async loadTsconfigJsonForFile (/path/to/project/node_modules/vite/dist/node/chunks/dep-9912c491.js:13664:24)
  at async transformWithEsbuild (/path/to/project/node_modules/vite/dist/node/chunks/dep-9912c491.js:13348:36)
  at async transformMain (/path/to/project/node_modules/@vitejs/plugin-vue/dist/index.mjs:2338:34)
  at async transform (/path/to/project/node_modules/rollup/dist/es/shared/node-entry.js:23183:16)

npm ERR! Lifecycle script `build` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: web@0.0.0 
npm ERR!   at location: /path/to/project/apps/web 
cngJo commented 1 year ago

Changing the tsconfig.json in apps/web to

{
    // https://nuxt.com/docs/guide/concepts/typescript
    "extends": "./.nuxt/tsconfig.json"
}

does the trick.

That confirms for me, that the issue is that we currently don't include the nuxt tsconfig in our project. Maybe there is a way around by explicitly importing the nuxt types 🤔

cngJo commented 1 year ago

Haha ...

changing the include to explicit include the .nuxt/nuxt.d.ts also works.

cngJo commented 1 year ago

Since this works now with #6, I'd close this in favor of #7 which is a more explicit issue regarding proper importing the nuxt tsconfig.json file.