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

vite/node project can't use i.e. jsr:@db/sqlite in package.json/node-compat mode. Migrating to deno.json will break resolution #26569

Open
birkskyum opened this issue Oct 26, 2024 · 11 comments
Labels
bug Something isn't working correctly bundler-resolution Issues caused by bundlers not supporting Deno resolution

Comments

@birkskyum
Copy link
Contributor

birkskyum commented Oct 26, 2024

Version: Deno 2.0.3

Say I try to run a project, like a new solid start example

  • deno run -A npm:create-solid
  • Select SolidStart, TypeScript, Basic

And then I port package.json over to deno.json

{
  "tasks": {
    "dev": "vinxi dev",
    "build": "vinxi build",
    "start": "vinxi start",
    "version": "vinxi version"
  },
  "imports": {
    "@solidjs/meta": "npm:@solidjs/meta@^0.29.4",
    "@solidjs/router": "npm:@solidjs/router@^0.14.10",
    "@solidjs/start": "npm:@solidjs/start@^1.0.9",
    "solid-js": "npm:solid-js@^1.9.2",
    "vinxi": "npm:vinxi@^0.4.3"
  }
}

Now it'll break because it can't resolve any dependencies from these npm: packages that doesn't have the "npm:"

 ➜ Local:    http://localhost:3000/
  ➜ Network:  use --host to expose

8:13:04 PM [vite] Pre-transform error: Failed to load url solid-js/web (resolved id: solid-js/web) in /Users/admin/repos/deno-kitchensink/solid-start-basic/src/entry-server.tsx. Does the file exist? (x5)
8:13:04 PM [vite] Pre-transform error: Failed to load url @solidjs/start/server (resolved id: @solidjs/start/server) in /Users/admin/repos/deno-kitchensink/solid-start-basic/src/entry-server.tsx. Does the file exist?
8:13:04 PM [vite] Error when evaluating SSR module /src/entry-server.tsx: failed to import "solid-js/web"
|- Error: Cannot find module 'solid-js/web' imported from '/Users/admin/repos/deno-kitchensink/solid-start-basic/src/entry-server.tsx'
    at nodeImport (/Users/admin/Library/Caches/deno/npm/registry.npmjs.org/vite/5.4.10/dist/node/chunks/dep-BWSbWtLw.js:53047:19)
    at ssrImport (/Users/admin/Library/Caches/deno/npm/registry.npmjs.org/vite/5.4.10/dist/node/chunks/dep-BWSbWtLw.js:52914:22)
    at undefined

Staying in package.json doesn't allow usage of jsr:@db/sqlite

@birkskyum birkskyum changed the title Moving to deno.json for vite/node project breaks vite/node project can't jsr:@db/sqlite in package.json mode, moving to deno.json will break resolution Oct 26, 2024
@birkskyum birkskyum changed the title vite/node project can't jsr:@db/sqlite in package.json mode, moving to deno.json will break resolution vite/node project can't use i.e. jsr:@db/sqlite in package.json mode, moving to deno.json will break resolution Oct 26, 2024
@birkskyum birkskyum changed the title vite/node project can't use i.e. jsr:@db/sqlite in package.json mode, moving to deno.json will break resolution vite/node project can't use i.e. jsr:@db/sqlite in package.json/node-compat mode, moving to deno.json will break resolution Oct 26, 2024
@birkskyum birkskyum changed the title vite/node project can't use i.e. jsr:@db/sqlite in package.json/node-compat mode, moving to deno.json will break resolution vite/node project can't use i.e. jsr:@db/sqlite in package.json/node-compat mode. Migrating to deno.json will break resolution Oct 26, 2024
@bartlomieju
Copy link
Member

@bartlomieju
Copy link
Member

Also look like there is a PR that tries to fix it too: vitejs/vite#18479

@birkskyum
Copy link
Contributor Author

@bartlomieju , when i have everything in deno.json and I enable the deno() plugin it does take some effect, but the server start still prints:

vinxi starting dev server
Failed to resolve dependency: solid-js, present in 'optimizeDeps.include'
Failed to resolve dependency: solid-js/web, present in 'optimizeDeps.include'
Failed to resolve dependency: solid-js/store, present in 'optimizeDeps.include'
Failed to resolve dependency: solid-js/html, present in 'optimizeDeps.include'
Failed to resolve dependency: solid-js/h, present in 'optimizeDeps.include'
Failed to resolve dependency: @solidjs/start > source-map-js, present in 'optimizeDeps.include'
Failed to resolve dependency: @solidjs/start > error-stack-parser, present in 'optimizeDeps.include'
Failed to resolve dependency: solid-js, present in 'optimizeDeps.include'
Failed to resolve dependency: solid-js, present in 'optimizeDeps.include' (x2)
Failed to resolve dependency: solid-js/web, present in 'optimizeDeps.include'
Failed to resolve dependency: solid-js/web, present in 'optimizeDeps.include' (x2)
Failed to resolve dependency: solid-js/store, present in 'optimizeDeps.include'
Failed to resolve dependency: solid-js/store, present in 'optimizeDeps.include' (x2)
Failed to resolve dependency: solid-js/html, present in 'optimizeDeps.include'
Failed to resolve dependency: solid-js/html, present in 'optimizeDeps.include' (x2)
Failed to resolve dependency: solid-js/h, present in 'optimizeDeps.include'
Failed to resolve dependency: solid-js/h, present in 'optimizeDeps.include' (x2)
Failed to resolve dependency: @solidjs/start > source-map-js, present in 'optimizeDeps.include'
Failed to resolve dependency: @solidjs/start > source-map-js, present in 'optimizeDeps.include' (x2)
Failed to resolve dependency: @solidjs/start > error-stack-parser, present in 'optimizeDeps.include'
Failed to resolve dependency: @solidjs/start > error-stack-parser, present in 'optimizeDeps.include' (x2)

@Ciantic
Copy link

Ciantic commented Oct 26, 2024

My PR won't fix this though, it's my attempt that is just not working for some reason.

I have pure repo example here: https://github.com/Ciantic/deno-pure-solid-start that has also issues...

I get errors like this:

[h3] [unhandled] Error: Failed to load url ./src/database.ts (resolved id: ./src/database.ts) in deno::TypeScript::@db/sqlite::C:/Users/jarip/AppData/Local/deno/remote/https/jsr.io/ff2127150c5fc24dbc6b1daba62c248f566cce7c9346539da1003b4019d972c2. Does the file exist?

@birkskyum
Copy link
Contributor Author

birkskyum commented Oct 26, 2024

@Ciantic, thansk! Maybe this ticket got a bit convoluted- maybe it's easiest to leave the jsr: issue for when SolidStart runs in deno.json.

@Ciantic
Copy link

Ciantic commented Oct 26, 2024

Basic solidStart works for me, in my attempt I get solidstart working without jsr packages.

As soon as I add jsr packages it fails.

@birkskyum
Copy link
Contributor Author

birkskyum commented Oct 26, 2024

@Ciantic Oh really, you can run SolidStart without a package.json? Can we use Stackblitz for deno to repro these things like I do all the time with Node?

@Ciantic
Copy link

Ciantic commented Oct 26, 2024

@birkskyum yes, try this https://github.com/Ciantic/deno-pure-solid-start/tree/main

Then click the counter button.

It will error only when clicking use server functions with jsr packages.

@birkskyum
Copy link
Contributor Author

birkskyum commented Oct 26, 2024

Aha, didn't know about the "dev": "deno run -A --node-modules-dir npm:vinxi dev" task syntax, just had vinxi dev... would have never guessed

@bartlomieju bartlomieju added bug Something isn't working correctly bundler-resolution Issues caused by bundlers not supporting Deno resolution labels Oct 26, 2024
@Ciantic
Copy link

Ciantic commented Oct 27, 2024

I've debugged it to somewhere in the loadAndTransform and transformRequest of vite, the call order is such.

First it always calls loadAndTransform and from there it gets a lot of relative URLs, like ./src/deno-sqlite-dialect.ts etc then fail to be transformed:

loadAndTransform deno::TypeScript::@soapbox/kysely-deno-sqlite::C:/Users/jarip/AppData/Local/deno/remote/https/jsr.io/ad3ae390e7fd79d5cf03ee16955d8caa114ad936157a5250fff3a45520a6cb09
transformRequest ./src/deno-sqlite-dialect.ts
transformRequest ./src/deno-sqlite3-dialect.ts
transformRequest ./src/poly-sqlite-dialect.ts
transformRequest ./src/poly-sqlite-driver.ts
transformRequest deno::TypeScript::@db/sqlite::C:/Users/jarip/AppData/Local/deno/remote/https/jsr.io/ff2127150c5fc24dbc6b1daba62c248f566cce7c9346539da1003b4019d972c2
loadAndTransform deno::TypeScript::@db/sqlite::C:/Users/jarip/AppData/Local/deno/remote/https/jsr.io/ff2127150c5fc24dbc6b1daba62c248f566cce7c9346539da1003b4019d972c2
transformRequest ./src/database.ts
transformRequest ./src/blob.ts
transformRequest ./src/statement.ts
transformRequest ./src/util.ts

I don't yet understand why it tries to do such a complicated thing for SSR modules.

@Ciantic
Copy link

Ciantic commented Oct 27, 2024

Good news everyone, I got jsr:@db/sqlite working just by using Deno's NPM compatibility mode, the .npmrc trick and using @jsr/db__sqlite import:

https://github.com/Ciantic/deno-solid-test/

⬆️ I've updated the above repository, and vite's dev server works now.

We have more problems in the nitro builder:

deno run -A build 
Task build vinxi build
vinxi v0.4.3


⚙  Building your app...
vinxi v0.4.3
(node:53524) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node.EXE --trace-warnings ...` to show where the warning was created)
ReferenceError: Deno is not defined
    at file:///C:/Source/JavaScript/solid-start-test/deno-solid-test/node_modules/.deno/@jsr+std__fs@0.221.0/node_modules/@jsr/std__fs/ensure_symlink.js:7:19
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)

However pure deno https://github.com/Ciantic/deno-pure-solid-start/ requires probably changes to Vite.

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 bundler-resolution Issues caused by bundlers not supporting Deno resolution
Projects
None yet
Development

No branches or pull requests

3 participants