empiricaly / empirica

Open source project to tackle the problem of long development cycles required to produce software to conduct multi-participant and real-time human experiments online.
https://empirica.ly/
Apache License 2.0
44 stars 8 forks source link

Client side JS rendering error re: browser-ponyfill.js does not provide an export named 'default' #449

Closed JamesPHoughton closed 9 months ago

JamesPHoughton commented 9 months ago

Is there an existing issue for this?

What happened?

After bumping to latest version, running the admin console is fine, but switching to participant view yields a JS error, and a blank page. (Nothing is rendered at all.)

From chrome browser console:

Uncaught SyntaxError: The requested module '/node_modules/cross-fetch/dist/browser-ponyfill.js?v=c60c6b24' does not provide an export named 'default' (at graphql.ts:219:3)

From firefox

Uncaught SyntaxError: ambiguous indirect export: default index.js:4:8

Which corresponds to:

image

From safari:

image

No errors serverside.

Steps To Reproduce

No response

Empirica Version

Version: v1.8.8
SHA:     c2176a6
Branch:  main
Time:    2023-12-03T08:21:53Z

Client:  1.8.8
Server:  1.8.8

What OS are you seeing the problem on?

macOS

What browser are you seeing the problem on?

No response

Relevant log output

No response

Anything else?

No response

Code of Conduct

JamesPHoughton commented 9 months ago

Looks like this is something other projects have encountered using graphql and cross-fetch: https://github.com/lquixada/cross-fetch/issues/120#issuecomment-1617172860

Some discussion in other projects about it being related to how the packages are linked: https://github.com/supabase/supabase-js/issues/845#issuecomment-1709307299

malsobay commented 9 months ago

@JamesPHoughton thanks for the detailed report -- just chiming in to say I'm also facing this. happy to share any diagnostics that are helpful, but I see obvious bases are already covered.

As an aside, is the documentation on changing to a specific version up-to-date? Tried doing $ empirica upgrade --version "version: v1.8.5" to roll back, but got ⠦ Upgrade empirica packages00:46:37.986 FTL empirica: failed to start error="upgrade packages: upgrade client: npm install --silent -E @empirica/core@version: v1.8.5: exit status 1"

Update: it looks like empirica upgrade --version "v1.8.5" works, I'll submit a PR for the docs.

npaton commented 9 months ago

Would mind trying to add the following to you client/package.json and then npm i and try again:

  "overrides": {
    "@empirica/core": {
      "@empirica/tajriba": "1.5.2"
    }
  }

Thanks!

JamesPHoughton commented 9 months ago

That worked great - what is it doing?

npaton commented 9 months ago

It forces a new version of tajriba I released, that polyfills fetch on the server. Unfortunately, the 2 libraries that handle browser and node cross platform support for fetch are broken in different ways, when using what they call a "ponyfill", which is where you don't overwrite the global definition of the thing you're trying to patch (here, fetch). So we're going for a full polyfill, which I'd rather not do, but I think it's fine. node-fetch is good. And I don't really have a choice at this point.

I'm releasing a new version with this fix.

npaton commented 9 months ago

This should be fixed in release 1.8.9.