Skip to content

start-node build uses different node-externals logic than dev #127

@katywings

Description

@katywings

IS: During npm run build the start-node adapter currently runs three build processes, one if them is a pure rollup build.

  1. That rollup build doesn't have vite's external-dependency detection magic
  2. it also ignores vites config ssr.external (code).

SHOULD:

  1. Ideallly that rollup build should have the same external dependency detection as vite (its a bad dev workflow if the dev/prod builds behave inconsistent)
  2. Atleast there should be a way for the user to manually set node externals consistently across dev and prod builds.

REPRODUCTION:

  • Essentially: use a node-only package (like redis) and run npm run build
  • Example

MY WORKAROUND:
I locally cloned start-node and made the following changes. This allows me to set externals in vite's ssr.external config consistently across dev/build.

diff --git a/packages/start-node/index.js b/packages/start-node/index.js
index 599c4bc..c1a189c 100644
--- a/packages/start-node/index.js
+++ b/packages/start-node/index.js
@@ -13,6 +13,7 @@ export default function () {
       import(pathToFileURL(join(config.root, "dist", "index.js")));
     },
     async build(config) {
+      const ssrExternal = config?.ssr?.external || [];
       const __dirname = dirname(fileURLToPath(import.meta.url));
       const appRoot = config.solidOptions.appRoot;
       await vite.build({
@@ -33,6 +34,7 @@ export default function () {
           outDir: "./.solid/server",
           rollupOptions: {
             input: resolve(join(config.root, appRoot, `entry-server`)),
+            external: ssrExternal,
             output: {
               format: "esm"
             }
@@ -54,7 +56,7 @@ export default function () {
           }),
           common()
         ],
-        external: ["undici", "stream/web", "@prisma/client"]
+        external: ["undici", "stream/web", "@prisma/client", ...ssrExternal]
       });
       // or write the bundle to disk
       await bundle.write({ format: "esm", dir: join(config.root, "dist") });

Somewhat related: #95

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions