Skip to content

RollupError with Cloudflare Pages Preset – Missing Semicolon in apiSwagger.js #3864

Closed

Description

@didagu

What version of Effect is running?

0.69.8

What steps can reproduce the bug?

  1. Set up a Nuxt 3 project (version 3.12.3).
  2. Install and use the uploadthing (7.2.0) package which heavily uses the @effect/platform package (version 0.69.8 with Effect 3.10.3).
  3. Configure Nuxt Nitro to use the cloudflare_pages preset.
  4. Run the pnpm run build command.
  5. Observe the build failure with the Expected a semicolon error message.

What is the expected behavior?

The build should complete successfully without syntax errors when using the cloudflare_pages preset, allowing deployment to Cloudflare Pages.

What do you see instead?

The build fails with a RollupError due to an expected semicolon in the apiSwagger.js file of the @effect/platform package.
Screenshot 2024-10-30 at 23 17 29

Additional information

Temporary Workaround: Switching to the node-server preset in nitro works but is not compatible with Cloudflare Pages deployment.

Activity

  1. added
    bug
    on Oct 30, 2024
  2. JamesCullum commented on Jan 26, 2025

    @JamesCullum

    Same issue, blocks all deployments to Cloudflare! Happy to hear if anyone found a workaround that still allows to deploy?

  3. didagu commented on Jan 26, 2025

    @didagu
    Author

    Same issue, blocks all deployments to Cloudflare! Happy to hear if anyone found a workaround that still allows to deploy?

    workaround might be to deploy with node-server preset instead of cloudflare_pages preset.

  4. JamesCullum commented on Jan 28, 2025

    @JamesCullum

    That doesn't allow deployments to Cloudflare. I currently have to wrap it with a Dockerfile and deploy it to a static Docker host with the node_server preset - which works, but means I can't use the performance and pricing from Cloudflare...

  5. didagu commented on Jan 28, 2025

    @didagu
    Author

    That doesn't allow deployments to Cloudflare. I currently have to wrap it with a Dockerfile and deploy it to a static Docker host with the node_server preset - which works, but means I can't use the performance and pricing from Cloudflare...

    I ended up using the CF images transform by URL feature to transform my R2 stored images, instead of using sharp.

  6. fubhy commented on Jan 28, 2025

    @fubhy
    Member

    Can I get a simple reproduction (plain pre-configured github repo) to ease the debugging for me? Happy to look into that then.

  7. JamesCullum commented on Jan 29, 2025

    @JamesCullum

    Thanks for your support! I have set up a simple minimalistic starter project and installed uploadthing, which provokes this error by using the effect package. You can clone and test here: https://github.com/JamesCullum/effect-issue-3864

    When you run "npm install" and "npm run build", you should encounter this issue.

  8. JamesCullum commented on Feb 16, 2025

    @JamesCullum

    @fubhy Any progress so far?

  9. fubhy commented on Feb 16, 2025

    @fubhy
    Member

    @fubhy Any progress so far?

    This is a bug in rollup because it should just not try to parse the string at all (it's trying to parse and process portions of a string, which is definitely not correcet). I've not researched further yet though.

    If you want to hotfix this on your side and you are not using the swagger or scalar UIs, you could apply a patch to apiSwappger.js and apiScalar.js (pnpm patch @effect/platform) and empty those strings these files export.

  10. fubhy commented on Feb 16, 2025

    @fubhy
    Member

    Ok, dug a bit deeper. It's not that Rollup is trying to parse the string, but rather that something in the build pipeline is replacing typeof window globally (even within strings) with "undefined". If you can find out what the heck is doing that, then you'll have found the culprit and can fix it there. But this is indeed not a bug in effect.

  11. fubhy commented on Feb 16, 2025

    @fubhy
    Member

    It's this here: https://github.com/nitrojs/nitro/blob/722d586cd73417d6aafedacc799179a9743be12f/src/rollup/config.ts#L254

    So it's a bug in nitro's rollup configuration it seems.

    Replacing values globally and arbitrarily without considering the AST is generally not a good idea. Reaching into strings for that for sure isn't.

  12. fubhy commented on Feb 16, 2025

    @fubhy
    Member

    This has been reported recently by another user too. I'd suggest to try and get this fixed in Nitro. The configuration for the rollup replace plugin is definitely overreaching and causing the problem here: nitrojs/nitro#3071

    You can also hotfix this in your configuration by replacin the incorrect typeof window replacement with something that works better in this context. Note that this is imho not a true fix and can lead to problems elsewhere.

      nitro: {
        preset: 'cloudflare',
        replace: {
          'typeof window': '`undefined`',
        },
      },
  13. JamesCullum commented on Feb 16, 2025

    @JamesCullum

    Thanks a lot for the great investigation and find! Now it fails at a different plugin, but at least that's a first-party dependency! Hopefully it's fixed on Rollup level!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions