AliceFox
AliceFox9mo ago

Moving code to src/ caused VSCode errors about imports

Hi. I just started a new project, and at first I had all my code in root workspace directory, together with deno.json. I had subdirectories also, but the main files were at the top. Everything worked just fine. Now I decided to move all code to src directory and it caused errors like this popping up in VSCode:
Relative import path "drizzle-orm/pglite" not prefixed with / or ./ or ../
hint: If you want to use a JSR or npm package, try running `deno add jsr:drizzle-orm/pglite` or `deno add npm:drizzle-orm/pglite`deno(import-prefix-missing)
Relative import path "drizzle-orm/pglite" not prefixed with / or ./ or ../
hint: If you want to use a JSR or npm package, try running `deno add jsr:drizzle-orm/pglite` or `deno add npm:drizzle-orm/pglite`deno(import-prefix-missing)
Now this errors is from src/db/index.ts. When I move it back to db/index.ts, it doesn't complain. Deno runs it just fine anyway, it's just the VSCode part that seems to not get it.
4 Replies
AliceFox
AliceFoxOP9mo ago
I managed to resolve it. Adding "deno.importMap": "./deno.json" to .vscode/settings.json fixed the issue, but I'm not sure why that is necessary.
$e.bash-tian
$e.bash-tian9mo ago
I am not sure what the issue could be, my guess is that is looks for a particular entry point and by adding src/ you are adding an extra layer There should probably be something about it in the docs
cbhscarter
cbhscarter3w ago
I'm experiencing a very similar issue. I have a main deno.jsonc file at the root level that contains a few aliases within the imports section. My code is located within a /src folder, with most in the /src/app folder. I have two aliases setup:
"@app/": "./src/app/",
"@shared/": "./src/app/shared/"
"@app/": "./src/app/",
"@shared/": "./src/app/shared/"
This works fine for most of my code. However, I also have a separate /tests folder that is a sibling of the /src folder. This tests folder has code that is trying to reference back to the original src code. I'm trying to use the @app alias to reference the code, but it's considering it as a relative import for some reason. (see image for the error)
No description
cbhscarter
cbhscarter3w ago
The issue was related to my deno compilerOptions not having the proper folder
"compilerOptions": {
...
"rootDirs": [".", "src", "src/.react-router/types", "tests"],
...
}
"compilerOptions": {
...
"rootDirs": [".", "src", "src/.react-router/types", "tests"],
...
}

Did you find this page helpful?