-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Problem with TypeScript module imports from pages within a multi-module Nuxt.js application (maybe ts alias problem 🤷♂️) #25116
Comments
Would you be able to provide a reproduction? 🙏 More infoWhy 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 prioritize it based on its severity and how many people we think it might affect. If 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 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: |
Please provide a running reproduction (e.g. via StackBlitz or CodeSandbox). You can exclude any kind of business logic, structure + minimal code is enough 👍 |
Reproduction link :https://codesandbox.io/p/devbox/eloquent-chatelet-gdvcy3 In the /modules/test module, it is evident that the index.vue page contains import errors. |
@EddyDezuraud to fix please leave only "extends" in tsconfig. You basically overwrite Nuxt's properties and it's aliases as well. I don't understand your original problem, but you can modify Nuxt's tsconfig by using according hook. You can also use P.S. Don't think this is related but your project must be ES Modules. Please convert require to be import and verify "type": "module" in your package.json |
Thank you for your feedback. I just tried removing the compilerOptions from the tsconfig. Indeed, the import of "#imports" is no longer completely red, but still shows an error. And for the other imports using the ~ alias, they are still not recognized. My issue lies in the fact that, when adding a module, imports with aliases like "~" or #imports return a TypeScript error in my IDE from a page within that module. |
Can you try to Invalidate Caches from File menu? With clearing file system cache Looks like a Webstorm issue to me here. Also:
|
I just performed an invalid cache & restart, but unfortunately, I still have the issue. This problem is also present in VsCode, so I believe it's not an IDE-related issue but rather something within my project. For additional information and clarification: However, the problem arises when I create an internal module: modules/moduleX/pages/xxx.vue. |
Maybe I haven't declared the pages for my new internal module correctly?
|
Yeah I have opened your repro.
That should do the trick. You can also move index.js inside module folder without changes. |
I did indeed fix the error on the sample repository. However, it doesn't resolve the issue related to the TypeScript errors: |
Do you see any fatal errors in console when starting the project? And don't forget to remove compilerOptions in sample repo |
Stackblits for some reason ignored .nuxt for me, so the types didn't work. Did you try it on your real project? |
I've made all the mentioned modifications to my actual project. However, it doesn't seem to have made any difference. Everything is working fine; there are no errors in the console, and the project launches and runs correctly. |
Really weird. Can you try to enable TS checking? Will it tell something interesting? Install |
For example, I just created a Git repository with a code sample similar to my implementation : |
Related? #25134 |
I'll play with it when I have a moment. Really interesting |
Environment
Reproduction
codesandbox.io/p/devbox/eloquent-chatelet-gdvcy3
Unfortunately, due to confidential elements of the project, providing a public repository is not possible.
However, I'll guide you on creating a simplified reproduction locally to demonstrate the import issue:
Project Structure:
Confirm that your project structure includes a module named "processus" with TypeScript files (e.g., store, components, etc.).
Module Setup:
On each module's root, the set of pages/components used for that module is defined using the example above.
TS Config:
After reviewing several issues more or less related to this topic, the following configuration was added to the tsconfig.json file.
Page index.vue
Describe the bug
I am currently facing issues with importing TypeScript modules from specific pages within a local module in an extended Nuxt.js application composed of multiple modules.
When attempting to import specific modules from pages located in the "processus" module, I receive the following errors in my IntelliJ IDE and also in VSCode:
Vue: Cannot find module ~/modules/processus/store/processus or its corresponding type declarations.
Vue: Cannot find module #imports or its corresponding type declarations.
Additional context
If I try to import with the same path and alias from a Vue file in the "components" folder of my process module, everything works perfectly.
I also want to add that the code runs completely without any issues, and the builds are functional as well. It's just that my IDE consistently highlights these imports in red.
Logs
No response
The text was updated successfully, but these errors were encountered: