Bundling of remote dependencies

I'm trying to import a function from a package that is browser first. That is exports: { browser: "..." } in package.json. As a reproductible example, I'm trying to import from remote
import { importSPKI, importPKCS8 } from "https://cdnjs.cloudflare.com/ajax/libs/jose/4.13.1/key/import.js";
import { importSPKI, importPKCS8 } from "https://cdnjs.cloudflare.com/ajax/libs/jose/4.13.1/key/import.js";
Error given:
service core:user:discuspal: Uncaught Error: No such module "https:/cdnjs.cloudflare.com/ajax/libs/jose/4.13.1/key/import.js".
imported from "worker.js"
✘ [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.
service core:user:discuspal: Uncaught Error: No such module "https:/cdnjs.cloudflare.com/ajax/libs/jose/4.13.1/key/import.js".
imported from "worker.js"
✘ [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.
Is there any parameter to enable bundling these dependency or do I have to roll my own Custom Build (https://developers.cloudflare.com/workers/wrangler/custom-builds/) ? If I do, is there an example repo that does this? I know my way around esbuild and don't mind copy&past a plugin that I wrote that can bundle remote dependencies.
4 Replies
grenierdev
grenierdevOP16mo ago
Please keep in mind that jose is only used to reproduce the issue and I understand that jose is supported. I'm just using it as a simple reproductible example.
zegevlier
zegevlier16mo ago
You can't import from a remote Url in workers. This is by design, as CF wants all code executed on workers so it can track down bugs / vulnerabilities. There might be a way to add it as part of a build step, but I'm afraid I can't help with that 😅
Hello, I’m Allie!
Can’t you just run Deno bundle?
grenierdev
grenierdevOP16mo ago
Indeed. I guess I'll need to figure out how custom build works.
Want results from more Discord servers?
Add your server