๐ Feature request: (intermediate value).require is not a function / import.meta is not supported
Which Cloudflare product(s) does this pertain to?
Workers Runtime
What version(s) of the tool(s) are you using?
3.17.1
What version of Node are you using?
No response
What operating system are you using?
Mac
Describe the Bug
[ERROR] service core:user:my-app: Uncaught TypeError: (intermediate value).require is not a function
at index.js:43523:22 in __require2
The problem is that my code / the generated bundle uses:
var __require = id => {
return import.meta.require(id)
}
And workerd provides an empty object for import.meta, thus import.meta.require is undefined and not a function.
Please provide a link to a minimal reproduction
No response
Please provide any relevant error logs
No response
Relabeling this as a feature request. We do not currently implement anything on import.meta.
Just wanted to share my experience with this coming out of conversations in this issue, and so hoping / looking forward to at least get support for import.meta.url ๐ค
Curious if there were any updates on this or sentiment from Cloudflare on supporting import.meta.url? I have now confirmed that in Netlify, Vercel, and AWS Lamba (using both raw upload, SST, and Architect) all have no issues with usage of import.meta.url in deployed function code, so would be great if Cloudflare could support this useful and long-standing web standard as well. ๐
I acknowledge Netlify and Vercel are derivatives of AWS, and they are all just running NodeJS under the hood, but I wanted to list them all individually mainly in terms of confirming that I wasn't just assuming, and incorrectly attributing support where it may not actually be there. For example, of couple of these providers / tools required opting-out of any pre / post processing they were doing, because in both cases I encountered this with; Netlify and SST, they were pre-bundling all function code with esbuild on their ends, which has had mixed support for import.meta.url and so the best results I found were where I just leveraged their systems for just putting the code in the right place for them to do their uploads / orchestration and nothing else.
So in that regard, in terms of being able to confidently recommend support to users that "yes, this will work" I just wanted to do my due diligence, and would love to include Cloudflare in that group! (and would personally love to start using Cloudflare more myself ๐ )
Thanks in advance! ๐งก
Import.meta.url will be coming this year. Don't have a more specific target yet
Great, thank you for the update!
Any news on this?
Re: import.meta.url โย if you enable new_module_registry and experimental compatibility flags to your Worker โ you'll see this implemented. Can't yet deploy to Cloudflare when using the new_module_registry compatibility flag, but we're working on that.
Re: import.meta.require โ right now that is Bun-specific, and called out in Bun docs as unstable, see: https://bun.com/reference/globals/ImportMeta/require
refs discussion in https://github.com/nodejs/node/pull/55730
Thanks for the update @irvinebroque , looking forward to when this would be testable on Cloudflare ๐