Error is thrown when building with solid-start-static
/home/projects/vitejs-vite-dxqnej/src/routes
Error: Command failed: node /home/projects/vitejs-vite-dxqnej/node_modules/.pnpm/[email protected]/node_modules/solid-ssr/static/writeToDisk.mjs /home/projects/vitejs-vite-dxqnej/.solid/server/server.js /home/projects/vitejs-vite-dxqnej/dist/public/*404.html /*404 --trace-warnings
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TypeError: event.env.getStaticHTML is not a function".] {
code: 'ERR_UNHANDLED_REJECTION'
}
at InternalError (https://vitejs-vite-dxqnej.w-corp.staticblitz.com/blitz.3e4f172269cb19a250be0dfdff1ab657cb850d0e.js:6:291731)
at exithandler (https://vitejs-vite-dxqnej.w-corp.staticblitz.com/blitz.3e4f172269cb19a250be0dfdff1ab657cb850d0e.js:6:838089)
at EventEmitter.prototype.emit (https://vitejs-vite-dxqnej.w-corp.staticblitz.com/blitz.3e4f172269cb19a250be0dfdff1ab657cb850d0e.js:6:155574)
at maybeClose (https://vitejs-vite-dxqnej.w-corp.staticblitz.com/blitz.3e4f172269cb19a250be0dfdff1ab657cb850d0e.js:6:965920)
at ChildProcess/this._handle.onexit (https://vitejs-vite-dxqnej.w-corp.staticblitz.com/blitz.3e4f172269cb19a250be0dfdff1ab657cb850d0e.js:6:956550)
at _onChildExit/< (https://vitejs-vite-dxqnej.w-corp.staticblitz.com/blitz.3e4f172269cb19a250be0dfdff1ab657cb850d0e.js:15:380871)
at _0x3e957c (https://vitejs-vite-dxqnej.w-corp.staticblitz.com/blitz.3e4f172269cb19a250be0dfdff1ab657cb850d0e.js:15:147507)
at _0x35599c/< (https://vitejs-vite-dxqnej.w-corp.staticblitz.com/blitz.3e4f172269cb19a250be0dfdff1ab657cb850d0e.js:15:147247)
at <anonymous> (<anonymous>) {
killed: false,
code: 1,
signal: null,
cmd: 'node /home/projects/vitejs-vite-dxqnej/node_modules/.pnpm/[email protected]/node_modules/solid-ssr/static/writeToDisk.mjs /home/projects/vitejs-vite-dxqnej/.solid/server/server.js /home/projects/vitejs-vite-dxqnej/dist/public/*404.html /*404 --trace-warnings',
stdout: '',
stderr: '[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TypeError: event.env.getStaticHTML is not a function".] {\n' +
" code: \x1B[32m'ERR_UNHANDLED_REJECTION'\x1B[39m\n" +
'}\n'
}
Repro: https://stackblitz.com/edit/vitejs-vite-dxqnej
Run pnpm build
This is something you should fix, but also its a situation that's not expected to work too well because you are doing ssr: false. Kind of beating the point of the static adapter.
If you build with a normal adapter. You can just skip the server and deploy the client as static. If you just want a shell.
Since the solid-start-static adapter has no documentation, it's unclear as to whether ssr should be enabled or not.
When I think of "static" I think of a set of HTML and JS files that can be hosted on GitHub Pages or Apache. There's no hydration involved, no API endpoints, no server-side code at all. Since all of those mechanisms are present as a result of enabling "ssr: true", one would naturally think that the correct choice would be to disable SSR.
Am I misinterpreting what "static" means?
Hmm.. this is an interesting question. For someone looking for truly CSR setup the static adapter is the only one that outputs no server so I can understand how we get here. However, the point of the static adapter is to prerender pages so without ssr you aren't really pre-rendering anything. I think we should consider the intersection of these options because I can see this being the logical place to go for someone who primarily wants CSR.
Like a Node or Cloudflare Workers adapter isn't actually what you are looking for. I think with ssr: false and static adapter we should just skip pre-rendering probably (outside of the index.html we generate for all ssr: false adapters)
I solved my problem by using vite-plugin-ssr
One solution discussed on discord was to not use solid-start for sites like these, but simply use Vite+Solid as @MrFoxPro suggested. Unfortunately this means you lose file-based routing. There was some talk about back-porting file-based routing to solid-router, but I'm not sure if there was any progress in that regard.
Yes, it would be nice if solid-start supported this use case, but honestly, it's not all that much work to set up a project with vanilla Vite. Most of the value-add of solid-start is in the realm of server data, which is not an issue in the case I am envisioning. But file-based routing is really nice to have for something like a documentation site, especially when combined with MDX.
When I think of "static" I think of a set of HTML and JS files that can be hosted on GitHub Pages or Apache.
I thought the exactly same, and came along here. So as of today there's no way of achieving this with solid-start, right?
I was building a prototype web app with a mock API server, and then I wanted to host it on GitHub Pages to quickly share it with other people. But I admit such use case is not very common.
EDIT: After some tweak (including ssr: true), I found serving dist/public files on static site appears actually working. If that's the case, I'm just curious what is the use of .solid or dist/server.js files...?
@kissge It's a bit confusing, but what is preventing me from deploying to github pages is not this bug, but a different bug: #514. This bug is mostly about the confusion about the ssr option.
It is possible, under some circumstances, to deploy to a static website using the current static adapter. For example, if you are deploying to the root of the domain - something not possible with GH pages, but possible with other kinds of hosting - you can get it to work. For example, if you are deploying to something like Vercel it's fairly easy.
However, from what I can tell, the current static adapter also generates a bunch of server-side code (server.js) - which then never gets run. So it "works", but it's not exactly what I would call polished at this point.
One solution discussed on discord was to not use solid-start for sites like these, but simply use Vite+Solid as @MrFoxPro suggested. Unfortunately this means you lose file-based routing. There was some talk about back-porting file-based routing to solid-router, but I'm not sure if there was any progress in that regard.
Yes, it would be nice if solid-start supported this use case, but honestly, it's not all that much work to set up a project with vanilla Vite. Most of the value-add of solid-start is in the realm of server data, which is not an issue in the case I am envisioning. But file-based routing is really nice to have for something like a documentation site, especially when combined with MDX.
vite-plugin-ssr provides file-based routing and could be extended.
@viridia
One solution discussed on discord was to not use solid-start for sites like these, but simply use Vite+Solid as @MrFoxPro suggested.
We intend to cover this case here. It is just has some issues right now.
But file-based routing is really nice to have for something like a documentation site, especially when combined with MDX.
SSG(static + ssr: true) is even better for that case than Client Side Rendering(ssr: false) I think.
However, from what I can tell, the current static adapter also generates a bunch of server-side code (server.js) - which then never gets run.
It runs at build time to static render the site in the typical ssr: true setting.
When I think of "static" I think of a set of HTML and JS files that can be hosted on GitHub Pages or Apache. There's no hydration involved, no API endpoints, no server-side code at all. Since all of those mechanisms are present as a result of enabling "ssr: true", one would naturally think that the correct choice would be to disable SSR. Am I misinterpreting what "static" means?
There might be some confusion here. We need that code to create the static content in the first place. All static pre-rendering does is change when it server renders. Otherwise you can just copy dist/public from any ssr: false build regardless of adapter and be on your way.
In setting up for SolidStarts next Beta Phase built on Nitro and Vinxi we are closing all PRs/Issues that will not be merged due to the system changing. If you feel your issue was closed in mistake. Feel free to re-open it after updating/testing against 0.4.x release. Thank you for your patience. See https://github.com/solidjs/solid-start/pull/1139 for more details.