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

TS2307: Cannot find module '#imports' or its corresponding type declarations. with webstorm #14880

Closed
simllll opened this issue Sep 12, 2022 · 6 comments

Comments

@simllll
Copy link

simllll commented Sep 12, 2022

Environment


  • Operating System: Linux
  • Node Version: v18.9.0
  • Nuxt Version: 3.0.0-rc.9
  • Nitro Version: 0.5.1
  • Package Manager: npm@8.19.1
  • Builder: vite
  • User Config: srcDir, typescript, head, loading, css, middleware, runtimeConfig, tailwindcss, modules, env, build
  • Runtime Modules: @nuxtjs/tailwindcss@5.3.3, ~/modules/dashboardcore.ts, ~/modules/auto-import-eslint.ts
  • Build Modules: -

Reproduction

as this is IDE related, there is no classical reproduction script possible. But it happens also with a plain nuxt3 project.
What I have in my setup:

#tsconfig.json 
{
        "extends": "./.nuxt/tsconfig.json",
        "compilerOptions": {
                "resolveJsonModule": true,
    "noImplicitAny": false,
                "paths": {
                        "~/*": ["src/*"],
                        "@/*": ["src/*"]
                },
                "types": ["@nuxt/types"]
        },
        "exclude": ["node_modules", "cypress"]
}

.nuxt/tsconfig.josn even has paths in it with "#imports":
image

Describe the bug

IDE doesn't resolve types anymore:
image

the funny thing is, if open the imports.d.ts, types are working in there. So it seems it's just not picking up the initial tsconfig settings. Maybe an IDE bug?

Additional context

tested in WebStorm 2022.2.1
Build #WS-222.3739.57, built on August 16, 2022
also restarted the typescript engine and other stuff,

Logs

No response

@simllll
Copy link
Author

simllll commented Sep 12, 2022

Okay, and just by opening a bug report, I found my issue ;-) I still had paths overwritten in my tsconfig. Removing this, fixes the issue ;-)

my tsconfig is now just:

{
	"extends": "./.nuxt/tsconfig.json",
	"compilerOptions": {
		"resolveJsonModule": true,
		"noImplicitAny": false
	},
	"exclude": ["node_modules", "cypress"]
}

@zoujiawei6
Copy link

I have a different situation, my directory structure is "~/nuxt/demo1":

  1. This error was also generated when I opened the "~/nuxt/" directory in vscode;
  2. But when I open "~/nuxt/demo1" directory in vscode, it works fine.

nuxtjs/i18n: useI18n(), useLocalePath()

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
@matthew-dean
Copy link

It took a LOT of trial and error for me to resolve this issue, so just jotting down some notes here in case this helps anyone else:

  1. I had repeated TypeScript failures when I used the typescript.tsConfig option in my Nuxt config, but NOT because of paths, but because of an extends statement. By default, all of our tsconfig.json files were extending from a root tsconfig.json file, but TypeScript did not like this at all. So my project root was extending from .nuxt/tsconfig.json and .nuxt/tsconfig.json was extending from the monorepo root. My guess is that Nuxt does not auto-generate / set the baseUrl directory (it should, I would consider this a bug), so it was using our monorepo's source root baseUrl property.
  2. If you do update the typescript.tsConfig directory, the nuxt server will restart but it will not update the tsconfig.json file. (This is another bug.) So, you need to wipe the .nuxt directory, run nuxt prepare (or pnpm nuxt prepare), and then restart the Volar TypeScript process.

@Rusinas
Copy link

Rusinas commented Nov 10, 2023

Using nuxt in monorepo and having the same issue. I am extending the tsConfig, everything works well except for paths with hash and this is annoying because I can't get types :(

@meddle1
Copy link

meddle1 commented Dec 23, 2023

@matthew-dean
Thank you, bro, you saved a bunch of my time. This solved my problem (in nuxt.config):
typescript: { tsConfig: { compilerOptions: { baseUrl: ".", }, }, },

@matthew-dean
Copy link

@meddle1 No problem!

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

6 participants