You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now, we have a separate script that actually bundles it and runs it:
import{EdgeRuntime}from"edge-runtime";import*asesbuildfrom"esbuild";// bundle the code in initialCode.jsconstinitialCode=esbuild.buildSync({entryPoints: ["./initialCode.js"],bundle: true,write: false,format: "esm",target: "es2019",// minify: true, // uncommenting this line "fixes" the issue}).outputFiles[0].text;construntime=newEdgeRuntime({
initialCode,});constresponse=awaitruntime.dispatchFetch("https://example.com");awaitresponse.waitUntil();
This throws the following error:
evalmachine.<anonymous>:6991
throw new TypeError("Failed to parse URL from " + input, { cause: err });
^
TypeError: Failed to parse URL from https://example.com
at new Request (evalmachine.<anonymous>:6991:19)
at EdgeRuntime.dispatchFetch (evalmachine.<anonymous>:2:21)
at file:///Users/threepointone/code/edge-runtime-bug/index.mjs:17:32
at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
[cause]: RangeError: Invalid code point NaN
at Function.fromCodePoint (<anonymous>)
at new URLStateMachine (evalmachine.<anonymous>:1533:49)
at module2.exports.basicURLParse (evalmachine.<anonymous>:2100:19)
at new URLImpl (evalmachine.<anonymous>:2825:31)
at exports.setup (evalmachine.<anonymous>:3020:16)
at new URL (evalmachine.<anonymous>:3074:26)
at new Request (evalmachine.<anonymous>:6989:25)
at EdgeRuntime.dispatchFetch (evalmachine.<anonymous>:2:21)
at file:///Users/threepointone/code/edge-runtime-bug/index.mjs:17:32
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
}
The workaround for this is to enable minify:true when bundling, and that makes the code work as expected.
Now, I'm not certain whether this is a bug with yjs, esbuild, or edge-runtime, but I suspect it's edge-runtime, because importing yjs in node works fine, as well as when it's bundled with esbuild. It's only when trying to import it inside edge-runtime that the error pops up. The stack trace implies an error with the url, which doesn't seem right.
We'd previously vendored the libs used by y-partykit (yjs, lib0, etc) to workaround a bug in edge-runtime vercel/edge-runtime#243, but it makes using other libs that include those libs difficult. So instead this patch removes the vendoring, and applies the other workaround (which is to set `minify:true`). The tradeoff for this workaround is that any "dev mode" code (i.e. code wrapped with `if (process.env.NODE_ENV !== 'production')`) will be removed. This is temporary and we'll remove it once the bug is fixed by edge-runtime.
We'd previously vendored the libs used by y-partykit (yjs, lib0, etc) to workaround a bug in edge-runtime vercel/edge-runtime#243, but it makes using other libs that include those libs difficult. So instead this patch removes the vendoring, and applies the other workaround (which is to set `minify:true`). The tradeoff for this workaround is that any "dev mode" code (i.e. code wrapped with `if (process.env.NODE_ENV !== 'production')`) will be removed. This is temporary and we'll remove it once the bug is fixed by edge-runtime.
Bug Report
Current behavior
Consider the following code to be run inside EdgeRuntime
All it does is import the yjs library and log it.
Now, we have a separate script that actually bundles it and runs it:
This throws the following error:
The workaround for this is to enable
minify:true
when bundling, and that makes the code work as expected.Now, I'm not certain whether this is a bug with yjs, esbuild, or edge-runtime, but I suspect it's edge-runtime, because importing yjs in node works fine, as well as when it's bundled with esbuild. It's only when trying to import it inside edge-runtime that the error pops up. The stack trace implies an error with the url, which doesn't seem right.
Expected behavior/code
The code doesn't crash.
Additional context/screenshots
I made a sample repo that reproduces the bug as described above - https://github.com/threepointone/edge-runtime-bug
The text was updated successfully, but these errors were encountered: