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

Cloudflare worker breaks with wrangler dev #14

Open
jerico-zoeh opened this issue Jan 2, 2025 · 3 comments · May be fixed by #15
Open

Cloudflare worker breaks with wrangler dev #14

jerico-zoeh opened this issue Jan 2, 2025 · 3 comments · May be fixed by #15

Comments

@jerico-zoeh
Copy link

Using sdk with cloudflare workers in dev environment breaks wrangler dev.

I am using:

"@codesandbox/sdk": "^0.0.10"

I have compatibility_flags = ["nodejs_compat"] in my wrangler.toml file

I am getting the following error when running wrangler dev

✘ [ERROR] service core:user:cs-test: Uncaught TypeError: The argument 'path' The argument must be a file URL object, a file URL string, or an absolute path string.. Received 'undefined'

    at null.<anonymous> (node:module:12:15) in createRequire
    at null.<anonymous> (index.js:14007:38) in createRequire
    at null.<anonymous> (index.js:14018:16)

After digging into to my node_modules I found that the node_modules/@codesandbox/sdk/dist/esm/index.edge.js file has the following content:

import {createRequire} from 'module'
const require = createRequire(import.meta.url)
// ... more code below

Where the const require is not used anywhere. When I commented it out and the code looked like this:

import {createRequire} from 'module'
// const require = createRequire(import.meta.url)
// ... more code below

Then it's working correctly and I can use the sdk to create and interact with sandboxes. So, import.meta.url is not available. If I use require to import @codesandbox/sdk then it works correctly but I don't want to do that. Could someone look into it or tell me a workaround?

Also would like to be sure if it is a config issue with cjs/esm :(

@CompuIves
Copy link
Member

Very interesting... I added that snippet recently for supporting Next.js, but so far it has mostly created issues. I will remove that banner from the esbuild config and cut a new release to make it work from the worker!

@CompuIves CompuIves linked a pull request Jan 2, 2025 that will close this issue
@CompuIves
Copy link
Member

Just published a new version of the SDK, could you try if it works for you now?

@jerico-zoeh
Copy link
Author

Hi. Thanks for the quick fix. I have tested this branch (fix/esm-start) and it works for my setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants