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

Remix build fails when adding Vanilla Extract CSS #6729

Closed
1 task done
kyle-lambert opened this issue Jun 30, 2023 · 1 comment
Closed
1 task done

Remix build fails when adding Vanilla Extract CSS #6729

kyle-lambert opened this issue Jun 30, 2023 · 1 comment

Comments

@kyle-lambert
Copy link

kyle-lambert commented Jun 30, 2023

What version of Remix are you using?

v1.18.0

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

  1. Fresh install remix: npx create-remix@latest
  2. Install Vanilla Extract CSS: npm install -D @vanilla-extract/css
  3. Create a root.css.ts file with the following:
import { style } from "@vanilla-extract/css";

export const root = style({
  background: "red",
  color: "#454545",
});
  1. import and use root styles in root.tsx:
import * as styles from "./root.css";
import { cssBundleHref } from "@remix-run/css-bundle";
import type { LinksFunction } from "@remix-run/node";
import {
  Links,
  LiveReload,
  Meta,
  Outlet,
  Scripts,
  ScrollRestoration,
} from "@remix-run/react";

export const links: LinksFunction = () => [
  ...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];

export default function App() {
  return (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <meta name="viewport" content="width=device-width,initial-scale=1" />
        <Meta />
        <Links />
      </head>
      <body className={styles.root}>
        <Outlet />
        <ScrollRestoration />
        <Scripts />
        <LiveReload />
      </body>
    </html>
  );
}

Expected Behavior

Remix would successfully build and display correct styles as per root.css.ts

Actual Behavior

Build fails with the following error:

 [ERROR] Build failed with 1 error:
node_modules/@vanilla-extract/integration/dist/vanilla-extract-integration.cjs.dev.js:338:10: ERROR: [plugin: vanilla-extract-plugin] Couldn't find parent package.json with a name field from '/Users/kylelambert/Documents/vanilla-extract-css-test/app' [plugin css-bundle-update-plugin]

    app/root.tsx:20:30:
      20 │ import { cssBundleHref } from "@remix-run/css-bundle";
         ╵                               ~~~~~~~~~~~~~~~~~~~~~~~

  This error came from the "onLoad" callback registered here:

    node_modules/@remix-run/dev/dist/compiler/plugins/cssBundlePlugin.js:47:12:
      47 │       build.onLoad({
         ╵             ~~~~~~

    at setup (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/@remix-run/dev/dist/compiler/plugins/cssBundlePlugin.js:47:13)
    at handlePlugins (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/esbuild/lib/main.js:1279:21)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)


✘ [ERROR] Couldn't find parent package.json with a name field from '/Users/kylelambert/Documents/vanilla-extract-css-test/app' [plugin vanilla-extract-plugin]

    node_modules/@vanilla-extract/integration/dist/vanilla-extract-integration.cjs.dev.js:338:10:
      338 │     throw new Error(`Couldn't find parent package.json with a nam...
          ╵           ^

    at getPackageInfo (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/@vanilla-extract/integration/dist/vanilla-extract-integration.cjs.dev.js:338:11)
    at createViteServer (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/@vanilla-extract/integration/dist/vanilla-extract-integration.cjs.dev.js:575:15)
    at Object.createCompiler (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/@vanilla-extract/integration/dist/vanilla-extract-integration.cjs.dev.js:656:23)
    at getCompiler (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/@remix-run/dev/dist/compiler/plugins/vanillaExtract.js:27:38)
    at /Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/@remix-run/dev/dist/compiler/plugins/vanillaExtract.js:141:24
    at requestCallbacks.on-load (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/esbuild/lib/main.js:1421:28)
    at handleRequest (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/esbuild/lib/main.js:723:19)
    at handleIncomingPacket (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/esbuild/lib/main.js:745:7)
    at Socket.readFromStdout (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/esbuild/lib/main.js:673:7)
    at Socket.emit (node:events:511:28)
    at addChunk (node:internal/streams/readable:332:12)
    at readableAddChunk (node:internal/streams/readable:305:9)
    at Readable.push (node:internal/streams/readable:242:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

  This error came from the "onLoad" callback registered here:

    node_modules/@remix-run/dev/dist/compiler/plugins/vanillaExtract.js:136:12:
      136 │       build.onLoad({
          ╵             ~~~~~~

    at setup (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/@remix-run/dev/dist/compiler/plugins/vanillaExtract.js:136:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async handlePlugins (/Users/kylelambert/Documents/vanilla-extract-css-test/node_modules/esbuild/lib/main.js:1326:9)

  The plugin "vanilla-extract-plugin" was triggered by this import

    app/root.tsx:19:24:
      19 │ import * as styles from "./root.css";
         ╵                         ~~~~~~~~~~~~
@kyle-lambert
Copy link
Author

Upon further investigation, this isn't an issue with Remix, or Vanilla Extract. VE looks for name in package.json to prepend to the virtual modules it creates. Solution is to add a package name in package.json as per this issue.

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

2 participants