Skip to content
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

Deno attempting to install from package.json and erroring in vscode even when bare specifier from package.json not referenced in code #18639

Closed
ChuckJonas opened this issue Apr 8, 2023 · 5 comments

Comments

@ChuckJonas
Copy link

ChuckJonas commented Apr 8, 2023

(Opened from #17916)

I have a project that is going to be a mono-repo with deno (for supabase functions) and react (or nextjs, not sure yet).

The file structure currently looks like this:

- src
  - index.ts # file using @supabase/supabase-js dep
- supabase
   - functions
     - Hello.ts # deno
- package.json #for my react app, or whatever

In my deno file, I can't seem to get the npm:openai to cache. I've repeatly run the action in vscode, but there error will not go away.

import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { Configuration, OpenAIApi } from "npm:openai"; 

console.log("Hello from Functions!");

serve(async (req) => {
  const { name } = await req.json();
  const data = {
    message: `Hello ${name}!`,
  };

  return new Response(JSON.stringify(data), {
    headers: { "Content-Type": "application/json" },
  });
});

When I open the vscode deno output console I see this:

Setting Deno configuration from: "./supabase/functions/tsconfig.json"
  Resolved configuration file: "file:///Users/jonas/code/myproject/supabase/functions/tsconfig.json"
  Auto-resolved package.json: "file:///Users/jonas/code/myproject/package.json"

Enabling import suggestions for: https://deno.land
Enabling import suggestions for: https://x.nest.land
Download https://x.nest.land/.well-known/deno-import-intellisense.json
Download https://intellisense.nest.land/deno-import-intellisense.json
Enabling import suggestions for: https://crux.land
Server ready.
Could not set npm package requirements. Error getting response at https://registry.npmjs.org/@supabase/supabase-js for package "@supabase/supabase-js": An npm specifier not found in cache: "@supabase/supabase-js", --cached-only is specified.

Maybe it doesn't actually have anything to do with this error?

PS: Also, I tried creating a "package.json" in the supabase/functions folder and I find it odd that it's resolving the one in the root instead of that one.

@dsherret
Copy link
Member

dsherret commented Apr 8, 2023

What version of Deno are you using?

@ChuckJonas
Copy link
Author

@dsherret

deno 1.32.2 (release, aarch64-apple-darwin)
v8 11.2.214.9
typescript 5.0.3

so... came across this reddit post... I ran the code deno run supabase/functions/hello.ts then reloaded vscode and now the issue is fixed. Seems like a bug with the LSP, unrelated to my package.json (the noise threw me off trail).

If this is a known issue, please close.

@dsherret
Copy link
Member

dsherret commented Apr 8, 2023

Please upgrade to the latest patch release (1.32.3). The latest patch has a fix that doesn’t install from the package.json in this scenario in the lsp.

Also, if not already set, the deno.enablePaths config setting might be useful for you in only enabling deno for the supabase/functions folder. Additionally for the future, the deno cache supabase/functions/hello.ts command might be handy for caching a file without running it, but run works too.

@ChuckJonas ChuckJonas changed the title Deno Loading node package.json even with deno.enablePaths set to subfolder Apr 8, 2023
@ChuckJonas
Copy link
Author

ChuckJonas commented Apr 8, 2023

hmm I just upgraded using brew, so I thought I'd be on the latest patch... Maybe I need to update my brew registry first (or try another method). I'll figure it out and let you know if that fixes it.

@dsherret
Copy link
Member

dsherret commented Apr 8, 2023

Oh, that sucks. The homebrew distribution is temporarily broken apparently: #18608

Also, deno.enablePaths doesn’t affect the package.json loading, but just makes it so Deno only analyzes and surfaces diagnostics in that folder. In 1.32.3, it still will load the package.json, but it won’t auto-install the package.json on cache.

Anyway, I’m pretty sure this issue is fixed so I’m going to close this issue, but feel free to comment back if not and I will reopen it.

@dsherret dsherret closed this as completed Apr 8, 2023
@dsherret dsherret changed the title Loading node package.json even with deno.enablePaths set to subfolder Deno attempting to install from package.json and erroring in vscode even when bare specifier from package.json not referenced in code Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants