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

Error is thrown when building with solid-start-static #325

Closed
MrFoxPro opened this issue Oct 17, 2022 · 10 comments
Closed

Error is thrown when building with solid-start-static #325

MrFoxPro opened this issue Oct 17, 2022 · 10 comments
Labels
adapter Related to adapters bug Something isn't working csr related to client render mode (ssr: false)

Comments

@MrFoxPro
Copy link
Contributor

MrFoxPro commented Oct 17, 2022

/home/projects/vitejs-vite-dxqnej/src/routes
Error: Command failed: node /home/projects/vitejs-vite-dxqnej/node_modules/.pnpm/solid-ssr@1.5.7/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/solid-ssr@1.5.7/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

@nksaraf
Copy link
Member

nksaraf commented Oct 18, 2022

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.

@viridia
Copy link

viridia commented Dec 3, 2022

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?

@ryansolid
Copy link
Member

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)

@ryansolid ryansolid added the bug Something isn't working label Dec 21, 2022
@MrFoxPro
Copy link
Contributor Author

I solved my problem by using vite-plugin-ssr

@viridia
Copy link

viridia commented Dec 23, 2022

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.

@kissge
Copy link

kissge commented Dec 25, 2022

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...?

@viridia
Copy link

viridia commented Dec 25, 2022

@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.

@MrFoxPro
Copy link
Contributor Author

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.

@ryansolid
Copy link
Member

ryansolid commented Dec 30, 2022

@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.

@ryansolid
Copy link
Member

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 #1139 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapter Related to adapters bug Something isn't working csr related to client render mode (ssr: false)
Projects
None yet
Development

No branches or pull requests

5 participants