denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.39k stars 5.18k forks source link

Support for Qwik #19854

Open zwn opened 11 months ago

zwn commented 11 months ago

Qwik uses vite so the basics should be there

However I am not having luck just trying to run vite as-is:

$ deno run --allow-read --allow-write --allow-env npm:create-qwik@latest
❌ Not implemented: net.Socket.prototype.constructor with fd option

If I use node to create default empty app and try running vite with deno I get a problem with sharp:

$ deno run -A --node-modules-dir npm:vite
error when starting dev server:
Error:
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp-linux-x64.node'
Require stack:
- /.../qwik-deno-plain/node_modules/.deno/sharp@0.32.3/node_modules/sharp/lib/sharp.js
- /.../qwik-deno-plain/node_modules/.deno/sharp@0.32.3/node_modules/sharp/lib/constructor.js
- /.../qwik-deno-plain/node_modules/.deno/sharp@0.32.3/node_modules/sharp/lib/index.js
- /.../qwik-deno-plain/node_modules/.deno/imagetools-core@4.0.3/node_modules/sharp/lib/index.js
...

That seems to be discussed here:

I have also tried using --node-modules-dir=true and populating the node_modules with pnpm and npm but that also didn't work.

It'd be great to be able to add qwik to create-vite-extra.

zwn commented 11 months ago

The dependency chain leading to sharp contains imagetools-core, vite-imagetools and finally qwik-city.

In the meantime, I tried just copying the files where they are being searched for but then I get:

$ deno run -A --node-modules-dir npm:vite --mode ssr
error when starting dev server:
Error: Platform not supported
    at loadPlatformBinding (file:///.../deno-qwik/node_modules/.deno/@builder.io+qwik@1.2.3/node_modules/@builder.io/qwik/optimizer.cjs:1329:11)
    at createOptimizer (file:///.../deno-qwik/node_modules/.deno/@builder.io+qwik@1.2.3/node_modules/@builder.io/qwik/optimizer.cjs:1355:93)
    at async Object.init2 [as init] (file:///.../deno-qwik/node_modules/.deno/@builder.io+qwik@1.2.3/node_modules/@builder.io/qwik/optimizer.cjs:1712:49)
    at async config (file:///.../deno-qwik/node_modules/.deno/@builder.io+qwik@1.2.3/node_modules/@builder.io/qwik/optimizer.cjs:3006:9)
    at async runConfigHook (file:///.../deno-qwik/node_modules/.deno/vite@4.4.4/node_modules/vite/dist/node/chunks/dep-abb4f102.js:66165:25)
    at async resolveConfig (file:///.../deno-qwik/node_modules/.deno/vite@4.4.4/node_modules/vite/dist/node/chunks/dep-abb4f102.js:65608:14)
    at async _createServer (file:///.../deno-qwik/node_modules/.deno/vite@4.4.4/node_modules/vite/dist/node/chunks/dep-abb4f102.js:64846:20)
    at async CAC.<anonymous> (file:///.../deno-qwik/node_modules/.deno/vite@4.4.4/node_modules/vite/dist/node/cli.js:743:24)
zwn commented 11 months ago

That most likely refers to qwik/src/optimizer/src/platform.ts#L134 where only node is checked for.

I was able to locally patch optimizer.cjs to return "node" instead of "deno" everywhere and I got a working qwik running with vite on top of deno!

$ deno run -A --node-modules-dir npm:vite --mode ssr

  VITE v4.4.4  ready in 869 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help

  ❗️ Expect significant performance loss in development.
  ❗️ Disabling the browser's cache results in waterfall requests.
TypeError: error sending request for url (http://127.0.0.1:5174/@imagetools/30cc83c729e1f02924a4bd4b3577beb89ee24555): error trying to connect: tcp connect error: Connection refused (os error 111)
    at async mainFetch (ext:deno_fetch/26_fetch.js:266:12)
    at async fetch (ext:deno_fetch/26_fetch.js:490:7)
    at async getInfoForSrc (file:///home/zbynek/nanogrid-ws/deno-qwik/node_modules/.deno/@builder.io+qwik@1.2.3/node_modules/@builder.io/qwik/optimizer.cjs:2836:19)
    at async file:///home/zbynek/nanogrid-ws/deno-qwik/node_modules/.deno/@builder.io+qwik@1.2.3/node_modules/@builder.io/qwik/optimizer.cjs:2864:22
8:23:49 PM [vite] page reload src/components/starter/hero/hero.tsx

Even the hot module reload worked like a charm.

So it seems just two things are needed

  1. deal with the sharp package
  2. support deno runtime in qwik optimizer in addition to node
zwn commented 11 months ago

I've realized I should have started with why: Not being able to use Deno for development with Qwik precludes us from using Deno KV Store.

pencilcheck commented 10 months ago

How about this one? https://qwik.builder.io/docs/deployments/deno/

zwn commented 10 months ago

How about this one? https://qwik.builder.io/docs/deployments/deno/

Please see my comment above:

I've realized I should have started with why: Not being able to use Deno for development with Qwik precludes us from using Deno KV Store.

The deployment adapter allows only deployment, not local development and testing.

birkskyum commented 10 months ago

blocked by