nuxt: Non-relative paths are not allowed when 'baseUrl' is not set. Typescript v5.2.2

Environment

  • Operating System: Windows_NT
  • Node Version: v18.15.0
  • Nuxt Version: 3.7.1
  • CLI Version: 3.8.3
  • Nitro Version: 2.6.3
  • Package Manager: pnpm@8.7.1
  • Builder: -
  • User Config: ssr, modules, ionic, vite
  • Runtime Modules: @nuxtjs/ionic@0.12.1, nuxt-electron@0.6.0
  • Build Modules: -

Reproduction

Upgrade nuxt project to use typescript@5.2.2

Describe the bug

Since upgrading to typescript@5.2.2 I get the following error in the self-generated tsconfig.json

image

{
  "extends": "./.nuxt/tsconfig.json"
}

Additional context

The root cause of the issue is actually due to the “#pwa” types path in the auto-generated ts-config.json

image

Logs

No response

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Reactions: 7
  • Comments: 19 (2 by maintainers)

Most upvoted comments

Here is working workaround in nuxt.config.ts

import { defineNuxtModule } from '@nuxt/kit';

...

modules: [
  '@kevinmarrec/nuxt-pwa',
  // Add this after pwa module
  defineNuxtModule({
    setup(_, nuxt) {
      nuxt.hook('prepare:types', ({ tsConfig }) => {
        // @ts-ignore
        tsConfig.compilerOptions.paths['#pwa'] = ['./.nuxt/types/pwa'];
      });
    },
  }),
],

Hi, I reproduce on ‘npx nuxi init nuxt-app’ with the nuxt.config.ts as follows :

export default defineNuxtConfig({
  devtools: { enabled: true },
  srcDir: 'src/',
  alias: {
    '@': 'src/',
  },
})

then npm run generate

To correct the problem I added baseUrl as follows :

export default defineNuxtConfig({
  devtools: { enabled: true },
  typescript: {
    tsConfig: {
      compilerOptions: {
        baseUrl: './',
      },
    },
  },
  srcDir: 'src/',
  alias: {
    '@': 'src/',
  },
})