Skip to content

Tailwind v4 based react app failing to run inside nodepod #54

@saadalimalik-unstuck

Description

@saadalimalik-unstuck

While native css based react apps are running, tailwind v4 apps are failing with 504 (Gateway Timeout)

console logs for npm install and npm run dev:

 [Process output] �[2K
�[32m✔�[0m �[1madded 93 packages�[0m �[2min 50.4s�[0m

nodepod.ts:90 [Process exit] 0
nodepod.ts:89 [Process error] 
> todo-app@0.0.0 dev
> vite --host


nodepod.ts:18 Server ready on port: 5173, url: http://localhost:5173/__virtual__/podf7a610a1/5173
main.tsx:1  GET http://localhost:5173/node_modules/.vite/deps/react_jsx-dev-runtime.js?v=49c7452b net::ERR_ABORTED 504 (Gateway Timeout)Understand this error
main.tsx:2  GET http://localhost:5173/node_modules/.vite/deps/react.js?v=49c7452b net::ERR_ABORTED 504 (Gateway Timeout)Understand this error
main.tsx:3  GET http://localhost:5173/node_modules/.vite/deps/react-dom_client.js?v=568b4d7d net::ERR_ABORTED 504 (Gateway Timeout)Understand this error
main.tsx:4  GET http://localhost:5173/src/index.css net::ERR_ABORTED 504 (Gateway Timeout)Understand this error
main.tsx:5  GET http://localhost:5173/src/App.tsx net::ERR_ABORTED 504 (Gateway Timeout)

the logs also show error for resolving lightningcss-wasm32-wasi, I dont know if its related:

Uncaught (in promise) Error: Package "lightningcss-wasm32-wasi" does not exist in the registry

nodepod.ts

import { Nodepod, NodepodProcess } from "@scelar/nodepod";
// import { htmlFile, serverFile } from "../mocks/server-files";

export let pod: Nodepod | null = null;

export async function initNodepod(options?: {
  onServerReady: (url: string) => void;
}) {
  pod = await Nodepod.boot({
    watermark: false,
    workdir: "/app",
    /* files: {
      "/app/index.js": serverFile,
      "/app/index.html": htmlFile,
    }, */
    allowedFetchDomains: null,
    onServerReady: (port, url) => {
      console.log(`Server ready on port: ${port}, url: ${url}`);
      options?.onServerReady(url);
    },
  });

  return pod;
}

export async function runCommand(command: string, args: string[] = []) {
  if (!pod) throw new Error("No pod instance initialized!");

  const hasRootPath = args.some((arg) => arg.startsWith("/"));

  const proc = await pod.spawn(command, args, {
    cwd: hasRootPath ? "/" : pod.cwd,
  });
  logProcessData(proc);
  await proc.completion;
}

export async function mountFiles(files: Record<string, string>) {
  if (!pod) throw new Error("No pod instance initialized!");

  const writeFilesPromises: Promise<void>[] = [];

  for (const [path, content] of Object.entries(files)) {
    writeFilesPromises.push(pod.fs.writeFile(path, content));
  }

  await Promise.all(writeFilesPromises);

  // // Patch package.json as per requirements
  // if (await pod?.fs.exists("/app/package.json")) {
  //   const packageJsonRaw = await pod.fs.readFile("/app/package.json", 'utf-8');
  //   let packageJson: any;
  //   try {
  //     packageJson = JSON.parse(packageJsonRaw);
  //   } catch (err) {
  //     console.warn("Could not parse package.json, skipping override patch");
  //     return;
  //   }

  //   let modified = false;
  //   if (!packageJson.overrides) {
  //     // If overrides section does not exist, add it
  //     packageJson.overrides = { "lightningcss": "npm:lightningcss-wasm@latest" };
  //     modified = true;
  //   } else if (packageJson.overrides.lightningcss !== "npm:lightningcss-wasm@latest") {
  //     // If lightningcss line does not exist or differs, patch it
  //     packageJson.overrides.lightningcss = "npm:lightningcss-wasm@latest";
  //     modified = true;
  //   }

  //   if (modified) {
  //     // Minify the JSON when writing; avoid trailing newline for reliability
  //     await pod.fs.writeFile("/app/package.json", JSON.stringify(packageJson, null, 2));
  //   }
  // }

  // console.log(await pod.fs.readFile('/app/package.json', 'utf-8'));
}

export async function startDevServer() {
  if (!pod) throw new Error("No pod instance initialized!");

  await runCommand("npm", ["install"]);
  await runCommand("npm", ["run", "dev"]);
}

export function logProcessData(proc: NodepodProcess) {
  proc.on("output", (text) => console.log("[Process output]", text)); // stdout
  proc.on("error", (text) => console.log("[Process error]", text)); // stderr
  proc.on("exit", (code) => console.log("[Process exit]", code));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions