Absolute import ambiguity? #12814
-
It seems like with a config like this: // jsconfig.json or tsconfig.json
{
"compilerOptions": {
"baseUrl": "."
}
} ...Next always tries to load npm modules first, then falls back to local. For example, if I have a file at Is there any recommendation for avoiding ambiguity here? I worry I now have to know the names of every single transient dependency in my project to avoid accidentally using a folder name that collides with one of my dependency names. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I tend to set my jsconfig.json like this:
So your import would be |
Beta Was this translation helpful? Give feedback.
-
I'd suggest a structure like this: {
"compilerOptions": {
"baseUrl": "node_modules",
"paths": {
"@/*": ["../*"]
}
}
} This prevents any ambiguity, and requires you perform absolute imports as so:
You'll know immediately if an import is for a npm module or absolute import, also, there's no namespace collisions with this approach. |
Beta Was this translation helpful? Give feedback.
-
Thanks @Timer, I like that solution! |
Beta Was this translation helpful? Give feedback.
I'd suggest a structure like this:
This prevents any ambiguity, and requires you perform absolute imports as so:
You'll know immediately if an import is for a npm module or absolute import, also, there's no namespace collisions with this approach.