workerd icon indicating copy to clipboard operation
workerd copied to clipboard

๐Ÿ› Feature request: (intermediate value).require is not a function / import.meta is not supported

Open schettn opened this issue 2 years ago โ€ข 1 comments

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

schettn avatar Nov 23 '23 22:11 schettn

Relabeling this as a feature request. We do not currently implement anything on import.meta.

jasnell avatar Oct 22 '24 17:10 jasnell

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 ๐Ÿคž

thescientist13 avatar Dec 02 '24 21:12 thescientist13

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! ๐Ÿงก

thescientist13 avatar Feb 21 '25 21:02 thescientist13

Import.meta.url will be coming this year. Don't have a more specific target yet

jasnell avatar Feb 21 '25 22:02 jasnell

Great, thank you for the update!

thescientist13 avatar Feb 21 '25 22:02 thescientist13

Any news on this?

astanciu avatar Jul 11 '25 19:07 astanciu

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

Image

refs discussion in https://github.com/nodejs/node/pull/55730

irvinebroque avatar Oct 26 '25 01:10 irvinebroque

Thanks for the update @irvinebroque , looking forward to when this would be testable on Cloudflare ๐Ÿ‘

thescientist13 avatar Oct 28 '25 00:10 thescientist13