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

Cannot use socket of cloudflare worker in cloudflare_module preset #2628

Open
zou-yu opened this issue Jul 20, 2024 · 2 comments
Open

Cannot use socket of cloudflare worker in cloudflare_module preset #2628

zou-yu opened this issue Jul 20, 2024 · 2 comments

Comments

@zou-yu
Copy link

zou-yu commented Jul 20, 2024

Environment

nodejs: 18
nighly build nuxt & nitro (same issue with nuxt 3.12, nitro 2.9)

Reproduction

import cloudflare socket in any eventHandler files in /server/api/xxx

import { connect } from "cloudflare:sockets";

You are going to get a errors when you run nuxt build or nuxt dev

Describe the bug

https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/

Cannot using cloudflare worker socket or any other cloudflare package likes cloudflare:xxx in cloudflare_module preset.
I wonder if this is a bug or just an unimplement feature?

Additional context

I try to add this to nuxt.config.ts, but it doesn't work:

build: {
    transpile: ['cloudflare:sockets']
  },
vite: {
  build: {
    rollupOptions: {
      external: ['cloudflare:sockets'],
    },
  },

},

Logs

run nuxt dev:

 WARN  "cloudflare:sockets" is imported by "server/api/email/send.post.ts", but could not be resolved – treating it as an external dependency.      7:42:32 PM

✔ Nuxt Nitro server built in 646 ms                                                                                                          nitro 7:42:32 PM
ℹ Vite client warmed up in 1ms                                                                                                                     7:42:32 PM
ℹ Vite server warmed up in 20ms                                                                                                                    7:42:32 PM

[7:42:33 PM]  ERROR  [worker reload] [worker init] Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'cloudflare:'

  at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:239:11)
  at defaultLoad (node:internal/modules/esm/load:130:3)
  at ModuleLoader.load (node:internal/modules/esm/loader:396:13)
  at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:56)
  at new ModuleJob (node:internal/modules/esm/module_job:67:26)
  at #createModuleJob (node:internal/modules/esm/loader:290:17)
  at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:247:34)
  at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:228:17)
  at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:21)

run nuxt build:

[nitro 7:43:50 PM]  ERROR  Error: Cannot resolve "cloudflare:sockets" from "/Users/zougengyu/Projects/supa-email/supa-email/server/api/email/send.post.ts" and externals are not allowed!


undefined


[7:43:50 PM]  ERROR  Cannot resolve "cloudflare:sockets" from "/Users/xxx/Projects/supa-email/supa-email/server/api/email/send.post.ts" and externals are not allowed!

  at Object.resolveId (node_modules/.pnpm/[email protected][email protected]/node_modules/nitro-nightly/dist/rollup/index.mjs:1570:17)
  at async PluginDriver.hookFirstAndGetPlugin (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:19643:28)
  at async resolveId (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18324:26)
  at async ModuleLoader.resolveId (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18727:15)
  at async Object.resolveId (node_modules/.pnpm/@[email protected][email protected]/node_modules/@rollup/plugin-commonjs/dist/es/index.js:590:10)
  at async PluginDriver.hookFirstAndGetPlugin (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:19643:28)
  at async resolveId (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18324:26)
  at async ModuleLoader.resolveId (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18727:15)
  at async node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:19031:50 



[7:43:50 PM]  ERROR  Cannot resolve "cloudflare:sockets" from "/Users/xx/Projects/supa-email/supa-email/server/api/email/send.post.ts" and externals are not allowed!
@dalbodeule
Copy link
Contributor

related here

Some names seem to be recognized as URLs sometimes, but they are actually often file or hook names.
It seems like there needs to be a procedure to check if it is a real library or a file or hook name.

@zou-yu
Copy link
Author

zou-yu commented Jul 26, 2024

related here

Some names seem to be recognized as URLs sometimes, but they are actually often file or hook names. It seems like there needs to be a procedure to check if it is a real library or a file or hook name.

thank you! you are so nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants