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

Bug: Cannot find vite #25616

Closed
marvinhagemeister opened this issue Sep 13, 2024 · 13 comments
Closed

Bug: Cannot find vite #25616

marvinhagemeister opened this issue Sep 13, 2024 · 13 comments
Assignees
Labels
bug Something isn't working correctly node compat

Comments

@marvinhagemeister
Copy link
Contributor

Steps to reproduce

  1. Create a deno.json with these contents:
{
  "imports": {
    "vite": "npm:vite@5.4.5"
  },
  "tasks": {
    "dev": "vite"
  }
}
  1. Create a vite.config.ts file with these contents:
import { defineConfig } from "vite";
export default defineConfig({});
  1. Run deno install
  2. Run deno task dev

Output:

$ deno task dev
Task dev vite
failed to load config from /Users/marvinh/dev/test/deno-vite-init/vite.config.ts
error when starting dev server:
Error: Cannot find module 'vite'
Require stack:
- /Users/marvinh/dev/test/deno-vite-init/vite.config.ts
- /Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/vite/5.4.5/dist/node/chunks/dep-CUvs3bbV.js
    at Function.Module._resolveFilename (node:module:616:15)
    at Function.Module._load (node:module:494:27)
    at Module.require (node:module:678:19)
    at require (node:module:802:16)
    at Object.<anonymous> (file:///Users/marvinh/dev/test/deno-vite-init/vite.config.ts:25:19)
    at Object.<anonymous> (file:///Users/marvinh/dev/test/deno-vite-init/vite.config.ts:31:4)
    at Module._compile (node:module:742:34)
    at Object._require.extensions.<computed> [as .js] (file:///Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/vite/5.4.5/dist/node/chunks/dep-CUvs3bbV.js:66642:16)
    at Module.load (node:module:659:32)
    at Function.Module._load (node:module:531:12)

Version: Deno 2.0.0-rc.2+606b7b1

@marvinhagemeister marvinhagemeister added bug Something isn't working correctly node compat labels Sep 13, 2024
@bartlomieju
Copy link
Member

You need to do nodeModulesDir: "auto" in config file

@marvinhagemeister
Copy link
Contributor Author

When I add nodeModulesDir: "auto" it doesn't find the vite command anymore:

$ deno task dev
Task dev vite
vite: command not found

@bartlomieju
Copy link
Member

That looks like a regression, indeed.

@nathanwhit
Copy link
Member

nathanwhit commented Sep 13, 2024

I'm fairly sure this never worked. We don't, in general, try to figure out what to autoinstall based just on a bin command.

@birkskyum
Copy link
Contributor

birkskyum commented Sep 13, 2024

I'm probably a bit old-fashioned here, but people who use vite are coming from node, and just talking for myself, I'm really intersted in a stable/fast manual flow, and not used to, or particularly interested in, anything related to package auto-installs. At least not if it's at the cost of a worse manual package install flow (I have the deno install crash on me every other time i manually add a package), or if it's introducing avoidable slowdowns like running an "implicit deno install before running a task"

@nathanwhit
Copy link
Member

nathanwhit commented Sep 13, 2024

at the cost of a worse manual package install flow (I have the deno install crash on me every other time i manually add a package)

Could you expand a bit on this? I'm not sure I follow

implicit deno install before running a task

Nevermind about that suggestion, that's not the right fix. I didn't think through it enough 😅

@birkskyum
Copy link
Contributor

birkskyum commented Sep 13, 2024

at the cost of a worse manual package install flow (I have the deno install crash on me every other time i manually add a package)

Could you expand a bit on this? I'm not sure I follow

Sure, I can see it's not so clear what I meant. I don't see any technical blockers for having both great manual/autoinstall flows - but in the case of prioritization/limited engineering time+resources (and there often is) I'd personally lean far towards making the new manual install / task execution flow absolutely stellar, before figuring out how to automate it.

@marvinhagemeister
Copy link
Contributor Author

FYI: I opened this issue because it occurred despite calling deno install manually.

@bartlomieju
Copy link
Member

@marvinhagemeister does the issue persist for you after you call deno install after adding nodeModulesDir configuration?

@birkskyum
Copy link
Contributor

birkskyum commented Sep 15, 2024

It works if the deno install is called after the nodeModulesDir: auto is added. (deno 2.0.0-rc.2)

If I set the nodeModuleDir:true I see a

Warning `"nodeModulesDir": true` is deprecated in Deno 2.0. Use `"nodeModulesDir": "auto"` instead`.

Instead of having to remember setting this, would it be possible to default nodeModulesDir: auto for deno 2, or even remove the nodeModulesDir, if the alternatives are deprecated and there's only the auto option left?

@bartlomieju
Copy link
Member

It works if the deno install is called after the nodeModulesDir: auto is added. (deno 2.0.0-rc.2)

If I set the nodeModuleDir:true I see a

Warning `"nodeModulesDir": true` is deprecated in Deno 2.0. Use `"nodeModulesDir": "auto"` instead`.

Instead of having to remember setting this, would it be possible to default nodeModulesDir: auto for deno 2, or even remove the nodeModulesDir, if the alternatives are deprecated and there's only the auto option left?

It's not the only option left, there's also local and manual. These will be visible once #25380 is addressed.

@nathanwhit
Copy link
Member

nathanwhit commented Sep 17, 2024

Oh I've just realized that @marvinhagemeister 's PR to vite (vitejs/vite#18081) will actually fix this as well.

The issue is that vite thinks that the deno project is CJS (fake ESM), so it transpiles it to CJS with require – which doesn't respect import maps in deno (and doesn't work super well with the global cache). After that PR, it doesn't transpile to CJS so it just works

@marvinhagemeister
Copy link
Contributor Author

Can confirm, updating to vite 5.4.7 which includes the fix resolves this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

No branches or pull requests

4 participants