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

Vue Router issue with upgrade of Nuxt 3.6.5 to 3.7.4 (tsconfig baseUrl) #23435

Closed
chrisjbr opened this issue Sep 27, 2023 · 3 comments · Fixed by #23440
Closed

Vue Router issue with upgrade of Nuxt 3.6.5 to 3.7.4 (tsconfig baseUrl) #23435

chrisjbr opened this issue Sep 27, 2023 · 3 comments · Fixed by #23440

Comments

@chrisjbr
Copy link

Environment

  • Node Version: v18.17.1
  • Nuxt Version: 3.7.4
  • Package Manager: npm@9.6.7

Reproduction

  1. Create new nuxt app npx nuxi@latest init my-app
  2. Add tsconfig.json at root level with the following content:
{
  "extends": "./.nuxt/tsconfig.json",
  "compilerOptions": {
    "baseUrl": "./.nuxt"
  }
}
  1. Import something from #vue-router:
<script setup lang="ts">
import { createRouter } from "#vue-router";
</script>

The following error message appears:

Module '"vue-router"' has no exported member 'createRouter'.ts(2305)

See Example on StackBlitz: https://stackblitz.com/edit/github-pzljlg. However, the error does not appear on StackBlitz, but only on a local project.

Describe the bug

Nuxt 3.7 removed the baseUrl in .nuxt/tsconfig.json. However, tools like Vitest and Storybook rely on the baseUrl in order to resolve path aliases.

  • Adding the baseUrl back into the project's tsconfig.json at the root level breaks existing imports from #vue-router.

    • ./nuxt/vue-router.d.ts contains the line: export * from 'vue-router', but it seems something isn't working correctly. Removing this file seems to remove the TypeScript issue.
  • The temporary solution for now is to create a new tsconfig.json file only for Vitest and Storybook. Only this config file contains the baseUrl.

Ideally, there would be a way to specify the baseUrl without breaking the import for vue-router. What would be the correct way to specify the baseUrl so that it works the same way as before the upgrade?

Additional context

No response

Logs

No response

@stackblitz
Copy link

stackblitz bot commented Sep 27, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@danielroe
Copy link
Member

danielroe commented Sep 27, 2023

baseUrl is removed as it is not recommended (and actually can cause issues):

This feature was designed for use in conjunction with AMD module loaders in the browser, and is not recommended in any other context. As of TypeScript 4.1, baseUrl is no longer required to be set when using paths.

https://www.typescriptlang.org/tsconfig#baseUrl

Ideally (alongside identifying what the issue is here) we should address this in storybook + vitest. Do you have issues to track in their repos?

@dwin0
Copy link

dwin0 commented Sep 28, 2023

Agree that storybook and vitest should be able to resolve the paths without the baseUrl, as it's no longer required. However, adding the baseUrl back into the tsconfig.json file should not break existing Nuxt imports, right?

What would be the correct way to import from #vue-router having the baseUrl in place? Because the path alias together with the baseUrl seem to point to the correct location (./nuxt/vue-router.d.ts).

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

Successfully merging a pull request may close this issue.

3 participants