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

🐛 BUG: Error when importing cloudflare:sockets from a script in a subfolder (scriptPath: "./dir/script.mjs") #1675

Closed
izidormaklary opened this issue Feb 15, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@izidormaklary
Copy link

Which Cloudflare product(s) does this pertain to?

Miniflare

What version(s) of the tool(s) are you using?

3.20240129.2 [Miniflare]

What version of Node are you using?

18.16.0

What operating system and version are you using?

Mac Sonoma 14.1.1

Describe the Bug

Observed behavior

Miniflare errors when trying to dynamically import the cloudflare:socket built-in module in a script that is nested in a directory.

So in a new Miniflare, a worker config including scriptPath: "./script.mjs" the dynamic import would work,
while scriptPath: "./dist/script.mjs" would cause it to crash: (No such module "dist/cloudflare:sockets).

Expected behavior

Builtins should not be imported from the directory defined in scriptPath.
(works well when the miniflare script is in the same directory as the script.

Please provide a link to a minimal reproduction

https://github.com/izidormaklary/miniflare-v3-monorepo-issue/tree/cloudflare-builtins-issue

Please provide any relevant error logs

Error: No such module "dist/cloudflare:sockets".

@izidormaklary izidormaklary added the bug Something isn't working label Feb 15, 2024
@penalosa penalosa transferred this issue from cloudflare/workers-sdk Feb 15, 2024
@kentonv
Copy link
Member

kentonv commented Feb 20, 2024

I think a work-around might be to prefix the module name with a /, like: import * from "/cloudflare:sockets";

@jasnell do the module registry changes you're working on fix this?

@izidormaklary
Copy link
Author

Thanks @kentonv but in my case the import is inside a package. So I just copy the builds of the internal packages I need into the miniflare directory, which is not the best but at least there won't be an unnecessary patch once it's fixed.

@jasnell
Copy link
Member

jasnell commented Feb 22, 2024

A fix for this landed in #1682 and should hopefully be in production by sometime next week.

@jasnell jasnell closed this as completed Feb 22, 2024
@github-project-automation github-project-automation bot moved this from Untriaged to Done in workers-sdk Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants