nksaraf / vinxi

The Full Stack JavaScript SDK
https://vinxi.vercel.app
MIT License
2.22k stars 80 forks source link

Using `consola` breaks build #365

Closed peterhirn closed 1 month ago

peterhirn commented 2 months ago
pnpm create solid
pnpm add consola

src/entry-server.tsx

import { consola } from "consola/basic";
const log = consola.withTag("a-tag");

pnpm build

⚙  Preparing app for node-server...
✔ Generated public .output/public                                                                                                                                                                                   vinxi 10:47:29 AM
ℹ Building Nitro Server (preset: node-server)                                                                                                                                                                       vinxi 10:47:29 AM

[vinxi 10:47:29 AM]  ERROR  Error: Could not load /home/peter/Projects/test/test-consola/node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/npm/consola/basic.mjs (imported by .vinxi/build/ssr/ssr.js): ENOENT: no such file or directory, open '/home/peter/Projects/test/test-consola/node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/npm/consola/basic.mjs'

undefined

[10:47:29 AM]  ERROR  Could not load /home/peter/Projects/test/test-consola/node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/npm/consola/basic.mjs (imported by .vinxi/build/ssr/ssr.js): ENOENT: no such file or directory, open '/home/peter/Projects/test/test-consola/node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/npm/consola/basic.mjs'

  at async open (node:internal/fs/promises:637:25)
  at async readFile (node:internal/fs/promises:1246:14)
  at async node_modules/.pnpm/rollup@4.21.2/node_modules/rollup/dist/es/shared/node-entry.js:19003:24
  at async Queue.work (node_modules/.pnpm/rollup@4.21.2/node_modules/rollup/dist/es/shared/node-entry.js:20028:32) 

[10:47:29 AM]  ERROR  Could not load /home/peter/Projects/test/test-consola/node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/npm/consola/basic.mjs (imported by .vinxi/build/ssr/ssr.js): ENOENT: no such file or directory, open '/home/peter/Projects/test/test-consola/node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/npm/consola/basic.mjs'

 ELIFECYCLE  Command failed with exit code 1.
madaxen86 commented 1 month ago

I have no problem building with vinxi 0.4.3 and consola 3.2.3

peterhirn commented 1 month ago

Thanks for the info. I just reproduced this again as described in my initial comment.

After that I reproduced it in a docker container to ensure this is not caused by some local state (ie. pnpm-store).

docker run -it --rm --entrypoint sh node:22.10.0-alpine

corepack enable
pnpm create solid@latest
...

All packages are up-to-date

{
  "name": "example-basic",
  "type": "module",
  "scripts": {
    "dev": "vinxi dev",
    "build": "vinxi build",
    "start": "vinxi start",
    "version": "vinxi version"
  },
  "dependencies": {
    "@solidjs/meta": "^0.29.4",
    "@solidjs/router": "^0.14.10",
    "@solidjs/start": "^1.0.9",
    "consola": "^3.2.3",
    "solid-js": "^1.9.2",
    "vinxi": "^0.4.3"
  },
  "engines": {
    "node": ">=18"
  },
  "packageManager": "pnpm@9.12.2+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228"
}
madaxen86 commented 1 month ago

Oh yeah, if you import from import { consola } from "consola/basic";it breaks. I had imported from import { consola } from "consola"; BUT ... Adding the alias to the server config solved it:

// app.config.ts
export default defineConfig({
  server: {
    alias: {
      consola: 'consola',
    },
  },
});

https://stackblitz.com/edit/github-vefktf?file=src%2Fentry-server.tsx,app.config.ts