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

Monorepo with Solid Start: [nitro] [unhandledRejection] TypeError: Cannot read properties of undefined (reading 'file') #1496

Open
2 tasks done
floratmin opened this issue Nov 4, 2024 · 1 comment

Comments

@floratmin
Copy link

floratmin commented Nov 4, 2024

Describe the bug

I have problems to build a project in a monorepo. As soon I add @vanilla-extract/vite-plugin to my project the build throws errors. I set up a monorepo to reproduce the error. To set up Solid Start I create a symlink with the node_modules folder.

cd apps/page/app
ln -s ../../../node_modules/ node_modules

Then I can build the app with nx build page-app, which throws errors.

When I remove crawlLinks: true from the file app.config.ts there is no build error, but a runtime error. When I change the file .output/server/chunks/nitro/nitro.mjs:4369:33 to log the id and manifest, I see that the id is an absolute path, whereas the keys in the manifest are relative paths. When I set up a project without monorepo the ids are relative and everything works.

I tried to pin down the error and I could fix it partially when I replaced the tsconfig.json with a config without the key extends and removing the Button element form Counter.tsx. Then it builds, but when loading the page it can not find the javascript bundle for the same reason, that there is an absolute path. I created a branch for this.

The error persists even when I remove the Button element and the increment class from the file Counter.tsx. So that no actual .css.ts file is used. As soon I remove the vanilla extract plugin from vite plugins everything works.

Serving with nx serve page-app works without any problems. I also set up a normal solidjs app where building with nx build tool-app and serving with nx serve tool-app works as expected.

Reproduction

https://github.com/floratmin/monorepo-vanilla-extract-vite-plugin-bug

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 5700G with Radeon Graphics
    Memory: 9.81 GB / 30.73 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 22.8.0 - ~/.nvm/versions/node/v22.8.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v22.8.0/bin/npm
    pnpm: 9.9.0 - ~/.local/share/pnpm/pnpm
  Browsers:
    Chrome: 130.0.6723.91
  npmPackages:
    @vanilla-extract/css: ^1.16.0 => 1.16.0 
    @vanilla-extract/recipes: ^0.5.5 => 0.5.5 
    @vanilla-extract/sprinkles: ^1.6.3 => 1.6.3 
    @vanilla-extract/vite-plugin: 4.0.17 => 4.0.17 
    rollup: 4.22.4 => 4.22.4 
    vite: 5.4.10 => 5.4.10

Used Package Manager

pnpm

Logs

⚙  Preparing app for node-server...
✔ Generated public .output/public                                               vinxi 10:06:29 AM
ℹ Initializing prerenderer                                                      vinxi 10:06:29 AM
ℹ Building Nitro Server (preset: nitro-prerender, compatibility date: ``)       vinxi 10:06:29 AM
✔ Nitro Server built                                                            vinxi 10:06:30 AM
✔ You can preview this build using npx serve .output/public                     vinxi 10:06:30 AM
ℹ Prerendering 1 initial routes with crawler                                    vinxi 10:06:30 AM
[nitro] [unhandledRejection] TypeError: Cannot read properties of undefined (reading 'file')
    at Object.get (file:///home/playground/workspace/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected]_pkkifnsbod3b7nmoc7jpr5cmom/node_modules/vinxi/lib/manifest/prod-server-manifest.js:168:33)
    at file:///home/playground/workspace/apps/page/app/.vinxi/prerender/chunks/nitro/nitro.mjs:1166:32
[nitro] [unhandledRejection] TypeError: Cannot read properties of undefined (reading 'file')
    at Object.get (file:///home/playground/workspace/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected][email protected]_pkkifnsbod3b7nmoc7jpr5cmom/node_modules/vinxi/lib/manifest/prod-server-manifest.js:168:33)
    at file:///home/playground/workspace/apps/page/app/.vinxi/prerender/chunks/nitro/nitro.mjs:1020:89

Validations

@floratmin
Copy link
Author

I could make it working with fixing the build process trough adding this plugin after the @vanilla-extract/vite-plugin.

import {Plugin} from 'vite';

export function fixVanillaExtract(): Plugin {
  const basePath = `${process.cwd()}/`;
  return {
    name: 'fix-vanilla-extract',
    renderChunk(code) {
      if (code.includes(basePath)) {
        return code.replaceAll(basePath, '')
      }
      return null;
    },
  };
}

I also added a branch to the repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant