vscode_deno icon indicating copy to clipboard operation
vscode_deno copied to clipboard

deno(no-cache-npm), even after caching

Open yacineMTB opened this issue 1 year ago • 6 comments

Describe the bug

import lodash from "npm:lodash";
console.log(lodash);

getting persistent red squigglies

To Reproduce

[kache@whitebox]$ code --version
1.76.0
92da9481c0904c6adfe372c12da3b7748d74bdcb
x64
[kache@whitebox scribepod2]$ deno --version
deno 1.31.1 (release, x86_64-unknown-linux-gnu) # arch btw
v8 11.0.226.13
typescript 4.9.4

extension version 3.17

  1. Install deno
  2. Attempt to import lodash from "npm:lodash"
  3. run it, deno caches the package correctly under ~/.cache/deno
  4. squigglies still there
  5. tried to run cache deps from vscode, squigglies persist
  6. tried to reload the window, squigglies persist
  7. tried to explicitly define den dir in workspace settings, squigglies persist

Expected behavior I'd expect that the red squigglies not be there

image

I can grease these things and figure it out. I just don't know how! If you can point me in a direction where I can get the LSP output, let me know. I just need a log of where it's trying to grab the dep out of, and why it's failing out on it. Let me know!

yacineMTB avatar Mar 04 '23 21:03 yacineMTB

I poked around a bit more I saw that there was an option to have the LSP logs out on some console, but I couldn't find it. What I did find though, is a process that gets spawned by vscode, which I'm pretty sure is the LSP. How do I get the logs?

Also, can I just disable the red squigglies? I don't really care that much, it just makes it hard to dev :P

yacineMTB avatar Mar 04 '23 21:03 yacineMTB

Go to the Output tab (Ctrl-Shift-U) and on the right dropdown pick "Deno Language Server".

Also, I found that an package.json (just an empty JSON {} is sufficient) is needed (otherwise the language server will pick up the "closest" package.json).

PAStheLoD avatar Mar 06 '23 01:03 PAStheLoD

I had the same issue. I addressed the errors in the logs and this was resolved. In my case I had hosts that were failing in my .vscode/settings.json file:

{
"deno.suggest.imports.hosts": {
"https://bad.url": true
}

DoubleOTheven avatar Mar 20 '23 19:03 DoubleOTheven

Same issue here, but my error was:

Could not set npm package requirements. Error getting response at https://registry.npmjs.org/@solidjs/router for package "@solidjs/router": An npm specifier not found in cache: "@solidjs/router", --cached-only is specified.

Fixed it with deno cache npm:@solidjs/router

keysmusician avatar Apr 23 '23 05:04 keysmusician

Same issue here. I solved it by delete deno.lock and delete cache directory(the one shown by deno info) and cache all the deps again. But still don't know why this happened.

MMMartt avatar Sep 11 '23 20:09 MMMartt

In my case, I had a package.json at the root of my repository and then I had deno.jsonc in a subfolder. I fixed the issue by:

  1. Creating a deno.jsonc at subdir (no contents are needed, only {})
  2. Change deno cache subdir/main.ts to cd subdir && deno cache main.ts
  • Otherwise deno will reuse the node_modules from the root directory, and will potentially overwrite dependencies installed by NPM (very dangerous).
  • Otherwise deno cache will not recognize the deno.jsonc as well.
  1. Add to .vscode/settings "deno.config": "subdir/deno.jsonc"

Now it works.

I also built a repo for reproduction: https://github.com/felipecrs/deno-vscode-npm-bug

I left instructions in the README.

Note however that I cannot trigger this specific issue (no-cache-npm even after clicking in cache) in the reproduction environment for some reason which I cannot explain (but I have one internal repo which I can consistently reproduce the issue although I fixed by following my instructions above).

The reproduction repo however at least highlights how deno is creating and installing dependencies at the top level node_modules while it should not.

felipecrs avatar Oct 06 '23 01:10 felipecrs