ERROR Could not resolve "cloudflare:workers"

Refactoring our working WebSockets to use Durable Objects with RPC methods. Using the Durable Object sample to start with no errors or warnings. But on build: ✘ [ERROR] Could not resolve "cloudflare:workers" src/durable-objects/testws.do.ts:3:30: 3 │ import { DurableObject } from 'cloudflare:workers' [@Cloudflare/workers-types 4.2 node v20.17.0 npm 10.8.2 ] Not sure if this is a package problem or config issue or what.. TIA for any direction
No description
No description
11 Replies
Brod
BrodOP4mo ago
oh interesting.. on 3.74.0 but when I update:
No description
Brod
BrodOP4mo ago
No idea how that devDependency got messed up. Fixed that. updated to ⛅️ wrangler 3.75.0 same: ✘ [ERROR] Could not resolve "cloudflare:workers" That was it! Mad at myself for not trusting the error handling message. Had to play with DO migrations a bit, but now have a new DO to build out our new WS connection. Very exciting. Thank you Skye - this was a major roadblock. Should have asked sooner.
zsmooth
zsmooth3mo ago
How do we satisfy eslint with this import? Is there a cloudflare template that has eslint set up that demonstrates? eslint doesn't know how to resolve cloudflare:workers, so it complains about import { DurableObject } from "cloudflare:workers";. I just shut it off though and things seem to work fine:
// eslint-disable-next-line import/no-unresolved
import { DurableObject } from "cloudflare:workers";
// eslint-disable-next-line import/no-unresolved
import { DurableObject } from "cloudflare:workers";
bkyerv
bkyerv2mo ago
how do we do it?
Aster
Aster2mo ago
Hey 👋 Same issue here, with "@cloudflare/workers-types to 4.20241022.0 (and set to same date in tsconfig: compilerOptions.types -> @cloudflare/workers-types/2024-10-22) + wrangler latest version, I get Cannot find module '@cloudflare:workers' or its corresponding type declarations. in my editor 🤔
Aster
Aster2mo ago
No description
bkyerv
bkyerv2mo ago
hopefully Skye will find time to help us out
Aster
Aster2mo ago
OKay it's working ,I had a typo in the code It's cloudflare:workers not @Cloudflare:workers
mr nooli
mr nooli2mo ago
exact same issue for me:
src/durable-object.ts:2:30:
2 │ import { DurableObject } from "cloudflare:workers";
src/durable-object.ts:2:30:
2 │ import { DurableObject } from "cloudflare:workers";
wondering the same
predaytor
predaytor2mo ago
same.. using @hono-rate-limiter/cloudflare setting in vite doesn't help either:
ssr: {
resolve: {
conditions: ['workerd', 'worker', 'browser'],
},
external: ['cloudflare:workers'],
},
ssr: {
resolve: {
conditions: ['workerd', 'worker', 'browser'],
},
external: ['cloudflare:workers'],
},
johannes
johannes2mo ago
Has anyone managed to solve this error with Vite? I use Hono with its Cloudflare dev server. My vite config looks like this, but I still get the same error that "cloudflare:workers" could not be resolved:
import build from '@hono/vite-build/cloudflare-workers';
import devServer from '@hono/vite-dev-server';
import cloudflareAdapter from '@hono/vite-dev-server/cloudflare';
import { defineConfig } from 'vite';

export default defineConfig(() => {
return {
build: {
minify: false,
rollupOptions: {
output: {
entryFileNames: '_worker.js',
},
external: ['cloudflare:workers'],
},
},
plugins: [
devServer({
adapter: cloudflareAdapter,
entry: './src/index.tsx',
}),
build(),
],
};
});
import build from '@hono/vite-build/cloudflare-workers';
import devServer from '@hono/vite-dev-server';
import cloudflareAdapter from '@hono/vite-dev-server/cloudflare';
import { defineConfig } from 'vite';

export default defineConfig(() => {
return {
build: {
minify: false,
rollupOptions: {
output: {
entryFileNames: '_worker.js',
},
external: ['cloudflare:workers'],
},
},
plugins: [
devServer({
adapter: cloudflareAdapter,
entry: './src/index.tsx',
}),
build(),
],
};
});
Want results from more Discord servers?
Add your server