Skip to content

Trying to do transpiled and bundled standalone server #1165

@thomasjm

Description

@thomasjm

Description

I would really like to build a server entrypoint that is not only transpiled (as in #562) but also bundled, so that the resulting dist folder is completely standalone. I don't want to worry about providing a separate node_modules folder in production with dependencies like express.

I filed an issue in vavite about this, but I think it may properly be solved at the Vike level. None of the solutions I could find online have worked, but I've come up with a solution which I think is really close. The demo repo is here:

https://github.com/thomasjm/vike-standalone

The idea is simple: I add an extra entry to build.rollupOptions.input pointing at the server/index_prod.js file. (For simplicity, I created a separate index_prod.js file, which is like index.js but with development stuff removed.) Then I set ssr.noExternal to prevent externalizing just about everything (except Node builtins).

At this point, I can build a dist folder which contains dist/server/index.mjs, and just about everything is bundled. The server actually starts up when you run it!

The only issue I'm tripping on is related to @brillout/vite-plugin-import-build. This is the point where I could really use some help, as it seems the tricks of this plugin aren't working in this scenario. The output is below. Could I trouble you @brillout ?

npm run try-standalone
...
Copying dist dir to /tmp/tmp.DO0XbUx8u7
Switching to dir and starting standalone server...
Server running at http://localhost:3000
...
Error: [@brillout/vite-plugin-import-build@0.2.18][Bug] You stumbled upon a bug in the source code of @brillout/vite-plugin-import-build. Reach out at https://github.com/brillout/vite-plugin-import-build/issues/new and include this error stack (the error stack is usually enough to fix the problem). A maintainer will fix the bug (usually under 24 hours). Don't hesitate to reach out as it makes @brillout/vite-plugin-import-build more robust. Debug info (this is for the @brillout/vite-plugin-import-build maintainers; you can ignore this): `{"distImporterDir":"/tmp/tmp.DO0XbUx8u7/dist/server","distImporterPathUnresolved":"/tmp/tmp.DO0XbUx8u7/dist/server/importBuild.cjs"}`
    at createErrorWithCleanStackTrace (file:///tmp/tmp.DO0XbUx8u7/dist/server/chunks/chunk-d66c6d0c.js:1907:11)
    at assert (file:///tmp/tmp.DO0XbUx8u7/dist/server/chunks/chunk-d66c6d0c.js:1968:93)
    at loadWithNodejs (file:///tmp/tmp.DO0XbUx8u7/dist/server/chunks/chunk-d66c6d0c.js:2235:24)
    at async Object.loadServerBuild$1 [as loadServerBuild] (file:///tmp/tmp.DO0XbUx8u7/dist/server/chunks/chunk-d66c6d0c.js:2181:15)
    at async loadImportBuild (file:///tmp/tmp.DO0XbUx8u7/dist/server/chunks/chunk-d66c6d0c.js:2254:5)
    at async initGlobalContext (file:///tmp/tmp.DO0XbUx8u7/dist/server/chunks/chunk-d66c6d0c.js:2853:26)
    at async renderPageAndPrepare (file:///tmp/tmp.DO0XbUx8u7/dist/server/chunks/chunk-d66c6d0c.js:6380:5)
    at async renderPage_wrapper (file:///tmp/tmp.DO0XbUx8u7/dist/server/chunks/chunk-d66c6d0c.js:6355:22)
    at async renderPage (file:///tmp/tmp.DO0XbUx8u7/dist/server/chunks/chunk-d66c6d0c.js:6371:48)
    at async file:///tmp/tmp.DO0XbUx8u7/dist/server/index.mjs:121876:25

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions