Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
abarke opened this issue Sep 12, 2023 · 19 comments
Open

Comments

@abarke
Copy link
Sponsor

abarke commented Sep 12, 2023

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

@github-actions
Copy link
Contributor

Would you be able to provide a reproduction? 🙏

More info

Why do I need to provide a reproduction?

Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.

What will happen?

If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect.

If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.

How can I create a reproduction?

We have a couple of templates for starting with a minimal reproduction:

👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox

A public GitHub repository is also perfect. 👌

Please ensure that the reproduction is as minimal as possible. See more details in our guide.

You might also find these other articles interesting and/or helpful:

@Quineone
Copy link

Quineone commented Sep 19, 2023

have the same issue,when yarn build (on nuxt layer)

Ignore, found out it is caused by the third party plugin, type generate.

@ymansurozer
Copy link

ymansurozer commented Sep 20, 2023

Same issue here. Happened for me after upgrading from 3.6.5 to 3.7.3.

And the error message is also interesting that there is no reference to a file, it says undefined:

 ERROR(vue-tsc)  Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?
 FILE  undefined:

@RayGuo-ergou
Copy link

The baseUrl option is not set in .nuxt/tsconfig.json

https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz?file=.nuxt%2Ftsconfig.json

@RayGuo-ergou
Copy link

Okay in this this PR , it removed for dev env support. I am guessing some dependencies still need baseUrl?

@RayGuo-ergou
Copy link

I found my issue, I defined an alias node_modules/.pnpm/@prisma+client@5.3.1_prisma@5.3.1/node_modules/.prisma/client/index-browser before upgrading to nuxt3.7. Just have to add ../ before it as node_modules/.pnpm/@prisma+client@5.3.1_prisma@5.3.1/node_modules/.prisma/client/index-browser is a none relative path.

Hope this helps

@abarke
Copy link
Sponsor Author

abarke commented Sep 22, 2023

Seems my issues bubbles down to the "#pwa" path in the auto-generated ts-config.json file. Manually changing it a "./.nuxt/types/pwa" fixes it. However this will just be overwritten on build.

image

@Quineone
Copy link

Seems my issues bubbles down to the "#pwa" path in the auto-generated ts-config.json file. Manually changing it a "./.nuxt/types/pwa" fixes it. However this will just be overwritten on build.

image

See this kevinmarrec/nuxt-pwa-module#109

@mo9a7i
Copy link

mo9a7i commented Oct 8, 2023

To override this temporarily, in your tsconfig.json override compilerOptions

{
  // https://nuxt.com/docs/guide/concepts/typescript
  "extends": "./.nuxt/tsconfig.json",
  "compilerOptions": {
    "paths": {
      "#pwa": [
        "./.nuxt/types/pwa"
      ],
    }
  }
}

@mo9a7i
Copy link

mo9a7i commented Oct 9, 2023

Just sharing thoughts, I might be wrong again too.

I stand corrected, applying the above solution caused some weird behavior in typescript in my project, leading to some variables being set as type unknown

The proper method to override the paths in ./.nuxt/tsconfig.json as per https://nuxt.com/docs/guide/concepts/typescript#nuxttsconfigjson is to use nuxt.config.ts alias property as below:

alias:{
    "#pwa": "./.nuxt/types/pwa"
},

@abarke
Copy link
Sponsor Author

abarke commented Oct 16, 2023

Just sharing thoughts, I might be wrong again too.

I stand corrected, applying the above solution caused some weird behavior in typescript in my project, leading to some variables being set as type unknown

The proper method to override the paths in ./.nuxt/tsconfig.json as per https://nuxt.com/docs/guide/concepts/typescript#nuxttsconfigjson is to use nuxt.config.ts alias property as below:

alias:{
    "#pwa": "./.nuxt/types/pwa"
},

This didn't work for me after adding the alias to nuxt.config.ts. The value generated in ./.nuxt/tsconfig.json is unchanged 😔

@mirik-k
Copy link

mirik-k commented Oct 21, 2023

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'];
      });
    },
  }),
],

@mo9a7i
Copy link

mo9a7i commented Nov 1, 2023

Cannot find name 'defineNuxtModule'.

@mirik-k
Copy link

mirik-k commented Nov 1, 2023

Cannot find name 'defineNuxtModule'.

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

@EvgenyWas
Copy link

Hi there! This problem is actual for me as well.
Environment:

  • Operating System: Windows_NT
  • Node Version: v20.9.0
  • Nuxt Version: 3.8.1
  • TypeScript version: 5.2.2
  • Package Manager: pnpm@8.12.1
  • User Config: ssr, vite
  • Additional Modules: vuetify
    image

@abarke

This comment was marked as off-topic.

@manniL
Copy link
Member

manniL commented Dec 25, 2023

To anyone experiencing the bug: To make sure we can have a look it is necessary to add a reproduction as described in #23157 (comment)

@TreyRuffy
Copy link

I also experienced the bug (with unchanged code from a working version so I could not create a reproduction) and found that deleting the node_modules folder by executing rm -rf node_modules fixed it.

@bchanez
Copy link

bchanez commented Mar 22, 2024

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/',
  },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests