josemarluedke / glimmer-apollo

Ember and Glimmer integration for Apollo Client.
https://glimmer-apollo.com
MIT License
39 stars 15 forks source link

[SSR error] environment.setHelperManager is not a function #45

Closed lifeart closed 3 years ago

lifeart commented 3 years ago

image

I got this if trying to render glimmerx app in ssr mode:

import { renderToString } from '@glimmerx/ssr';

import App from './App';

export function render() {
    return renderToString(App, {
        rehydrate: true,
    });
}

I see environment resolution problems in SSR mode, especially,

import 'glimmer-apollo/environment-glimmer' not working in nodejs (module not found), looks like it should be bundled to support nodejs execution or such

lifeart commented 3 years ago

reproduction app: https://github.com/lifeart/_glimmerx-apollo-ssr-issue

steps in readme section: https://github.com/lifeart/_glimmerx-apollo-ssr-issue#how-to-check

josemarluedke commented 3 years ago

@lifeart After a bit of trial and error, I saw that Vite is not using conditional exports correctly when doing SSR.

If you change the import to import 'glimmer-apollo/dist/cjs/environment-glimmer';, you will note that for the most part, it will work. After the SSR page is served, then we get the error for the client not finding the module. There were a few issues/prs in Vite around this problem, but they seem to be resolved/closed.

I did find another issue when running in node using Vite, a PR for that is coming: ReferenceError: self is not defined.

lifeart commented 3 years ago

closing, it, proposed solution (straightforward import) works just fine!

@josemarluedke thank you for your findings here and support!