QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.45k stars 1.26k forks source link

[🐞] Vanilla Node Server Adapter - Cannot find package 'undici' #6594

Closed RumNCodeDev closed 1 week ago

RumNCodeDev commented 1 week ago

Which component is affected?

Qwik Rollup / Vite plugin

Describe the bug

I am attempting to build and deploy a QwikCity Web App to Azure using the Node.js Server (Vanilla Node server) adapter. However after running the build command, and copy/paste the dist and server folders into a new directory and attempting to run node server/entry.node-server I get the following error

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'undici' imported from /.../test/server/entry.node-server.js

Reproduction

https://stackblitz.com/edit/vitejs-vite-q5swzr?file=index.html

Steps to reproduce

  1. Create a minimal qwik application via npm create qwik@latest and select Empty App.
  2. Use npm qwik add to add the Adapter: Node.js Server (Vanilla Node server)
  3. Build the application using build command from the package.json
  4. Copy/Paste the dist and server files into a new directory outside of the current project structure (like you would for a production deploy)
  5. Run node server/entry.node-server in the new directory

System Info

System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M3 Pro
    Memory: 440.39 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  npmPackages:
    @builder.io/qwik: ^1.5.7 => 1.5.7
    @builder.io/qwik-city: ^1.5.7 => 1.5.7
    @types/eslint: ^8.56.10 => 8.56.10
    @types/node: ^20.12.7 => 20.14.8
    @typescript-eslint/eslint-plugin: ^7.7.1 => 7.13.1
    @typescript-eslint/parser: ^7.7.1 => 7.13.1
    eslint: ^8.57.0 => 8.57.0
    eslint-plugin-qwik: ^1.5.7 => 1.5.7
    prettier: ^3.2.5 => 3.3.2
    typescript: 5.4.5 => 5.4.5
    undici: * => 6.19.2
    vite: ^5.2.10 => 5.3.1
    vite-tsconfig-paths: ^4.2.1 => 4.3.2

Additional Information

No response

gioboa commented 1 week ago

Hi @RumNCodeDev in that file there is an import from undici image you can add this dependency in the package.json and install it, then you can start the server correctly. image

we are importing crypto as well but we don't need to install it because node:internal manage it for us.

RumNCodeDev commented 1 week ago

@gioboa how would I accomplish that as part of the pipeline as thats a generated file?

gioboa commented 1 week ago

@gioboa how would I accomplish that as part of the pipeline as thats a generated file?

you can add a pnpm i undici step in your pipeline.

The original issue is solved, so I'm closing it for now. Feel free to re-open it if it's still an issue for you. Thanks.

RumNCodeDev commented 1 week ago

@gioboa , so if i do that, then i get another error for zod missing, and if i add that, then im missing @auth/core, and so on... so I feel like the adapter just isn't working properly if i have to keep just adding all of my deps again? Shouldnt this all be handled by the build step?

gioboa commented 1 week ago

Here you can find the Docker solution for a Qwik Node Server.

In a specific step is adding all the dependencies

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.yarn to speed up subsequent builds.
# Leverage bind mounts to package.json and yarn.lock to avoid having to copy them
# into this layer.
RUN --mount=type=bind,source=package.json,target=package.json \
   --mount=type=bind,source=yarn.lock,target=yarn.lock \
   --mount=type=cache,target=/root/.yarn \
   yarn install --frozen-lockfile

I think we can improve this process, but it's definitively a feature request.