MOtherMetroid
MOtherMetroid2mo ago

Deno.enable not working

https://docs.deno.com/runtime/manual/references/vscode_deno/#deno-enabling-a-workspace In another project, I manually created (in VSC) the root folder .vscode and the file settings.json with the content { "deno.enable": true } and it worked. In a new project (in the same workspace), I tried this again but it does not work in the editor: Cannot find module 'jsr:@std/dotenv' or its corresponding type declarations.ts(2307) When trying to run, it works fine. I'm using Deno 1.42.4 and VSCodium 1.88.1.24104
51 Replies
Deno AI Helper
Deno AI Helper2mo ago
It seems like you're encountering an issue where the Deno extension in Visual Studio Code (VSCode) isn't recognizing a module, even though running the code with Deno CLI works fine. Here are a few steps you can take to troubleshoot this issue, based on the documentation: 1. Ensure Deno is Enabled for the Workspace: The documentation states that you need to enable Deno for the workspace to have support for Deno APIs and module resolution. You've already created a .vscode/settings.json with { "deno.enable": true }, which is correct. However, make sure this setting is applied to the correct workspace folder if you're using a multi-root workspace. 2. Initialize Workspace Configuration: The documentation suggests using the "Deno: Initialize Workspace Configuration" command from the VSCode command palette. This sets up the necessary configuration and asks if you want to enable linting and unstable APIs. 3. Check for Workspace Folder Settings: If you're working with a multi-root workspace, you might need to enable Deno for specific workspace folders. The deno.enablePaths setting allows you to specify which sub-paths should be Deno-enabled. 4. Restart VSCode: Sometimes, changes to the settings might not take effect until you restart your editor. Try closing and reopening VSCode to ensure the settings are reloaded. 5. Check for Conflicting Extensions: Ensure that there are no other extensions that might conflict with the Deno extension, especially those related to TypeScript or JavaScript language services. 6. Check Deno Language Server Status: You can use the "Deno: Language Server Status" command from the command palette to check what the Deno language server thinks is your current active configuration. 7. **Disable TypeScript Project
Deno AI Helper
Deno AI Helper2mo ago
Diagnostics**: Make sure that the VSCode configuration enableProjectDiagnostics is disabled, as it can cause TypeScript language server to show errors that Deno should handle. If you've gone through these steps and the issue persists, it might be a bug with the Deno extension. In that case, consider searching for similar issues or reporting a new bug at the vscode_deno GitHub repository. Remember to check the exact path you're using for the module import. If there's a typo or incorrect path, that could also cause the module resolution to fail in the editor. 🦕
MOtherMetroid
MOtherMetroid2mo ago
So I have to guess no one knows anything about this? Can't continue using Deno in this state
marvinh.
marvinh.2mo ago
cc @nayeemrmn
lukeed
lukeed2mo ago
i started getting this too. just upgraded from 1.42.1 to 1.42.4 and everything stopped working lint & format settings ignored. cant find jsr (or any) packages
bartlomieju
bartlomieju2mo ago
@lukeed do you have the same problem if you update to latest Canary? (deno upgrade --canary)
lukeed
lukeed2mo ago
before i upgrade, to be clear, the cli works correctly its just the vscode aspect
bartlomieju
bartlomieju2mo ago
Yeah, vs code calls into CLI
lukeed
lukeed2mo ago
k 2s still happens my quick test is that saving file is formatting in a way that doesnt follow my deno.json fmt options as soon as i do deno.enablePaths = ["./deno.json"] the fmt config is respected but everything else breaks i hope https://github.com/denoland/vscode_deno/issues/1099#issuecomment-2028790434 is not here to stay, this is a breaking/awful change
bartlomieju
bartlomieju2mo ago
Alright, we'll look into that today
nayeemrmn
nayeemrmn2mo ago
This means ONLY deno.json is enabled. What enable-related settings did you have before?
lukeed
lukeed2mo ago
none. i allow/expect the entire project to be supported because of root deno.json existence but its ignored unless explicitly inserted into that array (following your comment)
nayeemrmn
nayeemrmn2mo ago
Okay, that was meant for people already using enablePaths. This is unexpected looking into it Does it work with enable: true?
lukeed
lukeed2mo ago
no well the file is completely ignored so any import map entries & any lint/fmt settings are ignored deno itself is still working, in that some linting/formatting is happening, but not as it should im back on 1.42.1 & everyhting works as exepected
nayeemrmn
nayeemrmn2mo ago
Do errors have like ts(2307) like OP, or is it deno-ts(2307) at the end?
lukeed
lukeed2mo ago
there are no errors, its working just not respecting my config
nayeemrmn
nayeemrmn2mo ago
Lastly, if you open the output panel by clicking the Deno <version> button at the bottom, does it mention the deno.json anywhere underneath Refreshing configuration tree...?
lukeed
lukeed2mo ago
lemme update again, 1s
nayeemrmn
nayeemrmn2mo ago
Just copy output panel contents
lukeed
lukeed2mo ago
yes, it finds all of them altho 1.42.1 only finds the root
nayeemrmn
nayeemrmn2mo ago
Yeah that's expected I think, does your file have some other empty deno.json closer to it?
lukeed
lukeed2mo ago
so whats probably happening is 1.42.4 is finding all & then looking for lint/fmt only in the first file? hwoever, it loops thru all w/ "applying import maps" there are no empty files
bartlomieju
bartlomieju2mo ago
@lukeed is that project open-source?
lukeed
lukeed2mo ago
not yet, here are the outputs
Starting Deno language server...
version: 1.42.4 (release, aarch64-apple-darwin)
executable: /Users/lukeed/.deno/bin/deno
Connected to "Visual Studio Code" 1.85.2
Refreshing configuration tree...
Resolved Deno configuration file: "file:///<project>/A/deno.json"
Resolved lockfile: "file:///<project>/A/deno.lock"
Resolved import map from configuration file
Resolved Deno configuration file: "file:///<project>/deno.json"
Resolved lockfile: "file:///<project>/deno.lock"
Resolved import map from configuration file
Resolved Deno configuration file: "file:///<project>/B/deno.json"
Resolved lockfile: "file:///<project>/B/deno.lock"
Resolved import map from configuration file
Resolved Deno configuration file: "file:///<project>/C/deno.json"
Resolved lockfile: "file:///<project>/C/deno.lock"
Resolved Deno configuration file: "file:///<project>/D/deno.json"
Resolved lockfile: "file:///<project>/D/deno.lock"
Enabling import suggestions for: https://deno.land
Server ready.


Starting Deno language server...
version: 1.42.1 (release, aarch64-apple-darwin)
executable: /Users/lukeed/.deno/bin/deno
Connected to "Visual Studio Code" 1.85.2
Refreshing configuration tree...
Resolved Deno configuration file: "file:///<project>/deno.json"
Resolved lockfile: "file:///<project>/deno.lock"
Resolved import map from configuration file
Enabling import suggestions for: https://deno.land
Server ready.
Starting Deno language server...
version: 1.42.4 (release, aarch64-apple-darwin)
executable: /Users/lukeed/.deno/bin/deno
Connected to "Visual Studio Code" 1.85.2
Refreshing configuration tree...
Resolved Deno configuration file: "file:///<project>/A/deno.json"
Resolved lockfile: "file:///<project>/A/deno.lock"
Resolved import map from configuration file
Resolved Deno configuration file: "file:///<project>/deno.json"
Resolved lockfile: "file:///<project>/deno.lock"
Resolved import map from configuration file
Resolved Deno configuration file: "file:///<project>/B/deno.json"
Resolved lockfile: "file:///<project>/B/deno.lock"
Resolved import map from configuration file
Resolved Deno configuration file: "file:///<project>/C/deno.json"
Resolved lockfile: "file:///<project>/C/deno.lock"
Resolved Deno configuration file: "file:///<project>/D/deno.json"
Resolved lockfile: "file:///<project>/D/deno.lock"
Enabling import suggestions for: https://deno.land
Server ready.


Starting Deno language server...
version: 1.42.1 (release, aarch64-apple-darwin)
executable: /Users/lukeed/.deno/bin/deno
Connected to "Visual Studio Code" 1.85.2
Refreshing configuration tree...
Resolved Deno configuration file: "file:///<project>/deno.json"
Resolved lockfile: "file:///<project>/deno.lock"
Resolved import map from configuration file
Enabling import suggestions for: https://deno.land
Server ready.
bartlomieju
bartlomieju2mo ago
Okay, and the fmt/lint config is not applied in any file? Or just certain files?
nayeemrmn
nayeemrmn2mo ago
What's the relative path of the file you're interested in? What should happen is import map uses the root deno.json only, lint and fmt settings respect the most local deno.json
lukeed
lukeed2mo ago
import maps do appear to be working; mis remembered sorry. this is now rly w/ linting & formatting rules not applied to any files in 1.42.4
nayeemrmn
nayeemrmn2mo ago
Okay, you have to copy all your linting and formatting rules to all deno.json's. We don't apply inheritance yet, can fix this soon. It worked in previous versions because the more local deno.json's weren't respected at all
lukeed
lukeed2mo ago
i also have no root .ts files, so if im following your theory, what may be happening in 1.42.4 is that A/foo.ts is loading A/deno.json only & since it finds no lint/fmt rules there, it uses Deno defaults instead of continuing to the root deno.json config (as it did before) you did/were before. it works great in 1.42.1
nayeemrmn
nayeemrmn2mo ago
Yeah, before A/deno.json wasn't read at all by the LSP
lukeed
lukeed2mo ago
oh i just read rest of message 🙈 sorry
bartlomieju
bartlomieju2mo ago
FYI @lukeed we will be releasing v1.43.0 tomorrow morning, we will try to fix it by then, but if we can't it will be fixed in the next patch release
lukeed
lukeed2mo ago
ok, thanks both i guess my final feedback here is that 1) im rly loving deno; but 2) in trying to chase this down since last night, ive realized that an area where Deno could/should improve is maintaining an actual changelog
bartlomieju
bartlomieju2mo ago
That's great to hear. We'll work on some solutions to provide better changelog for patch releases
lukeed
lukeed2mo ago
eg, theres only 1 mention of workspace on this page https://github.com/denoland/deno/releases & ~2 hours spent diving thru issues, comments, blog & docs only yielded https://github.com/denoland/vscode_deno/issues/1099#issuecomment-2028790434 as closest result
bartlomieju
bartlomieju2mo ago
Got it, workspaces are still very much experimental and poorly documented, but will improve the docs on them
bartlomieju
bartlomieju2mo ago
GitHub
suggestion: document workspaces functionality · Issue #415 · denola...
This is important as the Deno Standard Library will become a workspaces-enabled codebase once it is fully ported to JSR. Documenting how workspaces work will be important to those maintaining and c...
lukeed
lukeed2mo ago
happy to give addl feedack as you continue working thru them all my deno projects are monorepos / "workspaces"
bartlomieju
bartlomieju2mo ago
Yes! That would be very useful, just to be clear are you using workspaces setting in deno.json?
lukeed
lukeed2mo ago
which is why this latest upgrade blew up on me 😅 nope, didnt know it existed haha. again, it was jsut a structure i imported/started doing & it happened to work
bartlomieju
bartlomieju2mo ago
Got it, alright, I'll make sure we address the workspaces docs
lukeed
lukeed2mo ago
( it's also not in the json schema for deno.json definition, so vscode isnt suggesting the key )
bartlomieju
bartlomieju2mo ago
We'll add it right away
MOtherMetroid
MOtherMetroid2mo ago
Thanks for looking into this! Feel free to ping me when a new version is live with a fix. Ah, maybe this will also fix VSC ignoring the import map? Same thing basically, the editor can't resolve imports from the import map. But when running the file, it works as it's supposed to.
bartlomieju
bartlomieju2mo ago
It should be available in canary version in ~1h @lukeed @MOtherMetroid this fix is now available on canary if you wanna try it
MOtherMetroid
MOtherMetroid2mo ago
Gonna try tomorrow, it's past midnight for me. :fast_deno:
lukeed
lukeed2mo ago
seems to be working great, thanks @nayeemrmn @bartlomieju! (even without workspace config anywhere)
MOtherMetroid
MOtherMetroid2mo ago
Huh, it didn't fix it for me. But just now, when I created a deno.json file, the error was gone... even though the file is completely empty. Is this expected behaviour? Edit: Turns out deno.enable isn't even needed? I'm confused @.@ Import maps are still not resolved in the editor 😦 deno.json
{
"imports": {
"dotenv": "jsr:@std/dotenv"
}
}
{
"imports": {
"dotenv": "jsr:@std/dotenv"
}
}
main.ts
import { load } from 'dotenv'
import { load } from 'dotenv'
Relative import path "dotenv" not prefixed with / or ./ or ../deno(import-prefix-missing) This should be how it's supposed to work though, right?
lukeed
lukeed2mo ago
ya, by default (i think still) you dont need it if there's a deno.json file in your project root make sure you restart vscode or reload workspace after doing the canary upgrade otherwise the old lsp will still be running
bartlomieju
bartlomieju2mo ago
@MOtherMetroid if it still doesn't work, could you please open an issue in https://github.com/denoland/deno/issues with as much info as possible about your setup?
GitHub
Issues · denoland/deno
A modern runtime for JavaScript and TypeScript. Contribute to denoland/deno development by creating an account on GitHub.