I’m getting this Error while using “Wrangler dev” to Develop JS Api with Node runtime to deploy on Cloudflare Serverlessly.
wrangler.toml
#:schema node_modules/wrangler/config-schema.json
name = "imdb-api"
main = "src/index.ts"
compatibility_date = "2024-06-20"
# Automatically place your workloads in an optimal location to minimize latency.
# If you are running back-end logic in a Worker, running it closer to your back-end infrastructure
# rather than the end user may result in better performance.
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
# [placement]
# mode = "smart"
#Node compatibility
node_compat = true
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
# Docs:
# - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
# Note: Use secrets to store sensitive data.
# - https://developers.cloudflare.com/workers/configuration/secrets/
# [vars]
# MY_VARIABLE = "production_value"
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
# [ai]
# binding = "AI"
# Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
# [[analytics_engine_datasets]]
# binding = "MY_DATASET"
# Bind a headless browser instance running on Cloudflare's global network.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
# [browser]
# binding = "MY_BROWSER"
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
# [[d1_databases]]
# binding = "MY_DB"
# database_name = "my-database"
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
# [[dispatch_namespaces]]
# binding = "MY_DISPATCHER"
# namespace = "my-namespace"
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
# [[durable_objects.bindings]]
# name = "MY_DURABLE_OBJECT"
# class_name = "MyDurableObject"
# Durable Object migrations.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
# [[migrations]]
# tag = "v1"
# new_classes = ["MyDurableObject"]
# Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
# [[hyperdrive]]
# binding = "MY_HYPERDRIVE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
# [[kv_namespaces]]
# binding = "MY_KV_NAMESPACE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
# [[mtls_certificates]]
# binding = "MY_CERTIFICATE"
# certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
# [[queues.producers]]
# binding = "MY_QUEUE"
# queue = "my-queue"
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
# [[queues.consumers]]
# queue = "my-queue"
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
# [[r2_buckets]]
# binding = "MY_BUCKET"
# bucket_name = "my-bucket"
# Bind another Worker service. Use this binding to call another Worker without network overhead.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"
# Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
# [[vectorize]]
# binding = "MY_INDEX"
# index_name = "my-index"
[triggers]
crons = [ "* * * * *" ]
[build]
command="npm run"
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"declaration": true,
"sourceMap": true,
"esModuleInterop": true,
"inlineSourceMap": false,
"lib": ["esnext","dom"],
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"pretty": true,
"resolveJsonModule": true,
"rootDir": ".",
"skipLibCheck": true,
"strict": false,
"traceResolution": false,
"outDir": "",
"target": "esnext",
"module": "esnext",
"types": [
"@types/node",
"@types/service-worker-mock",
"@cloudflare/workers-types/2023-07-01"
]
},
"exclude": ["node_modules", "dist", "tests"],
"include": ["src", "scripts"]
}
# Package.json
{
“name”: “cloudflare-workers-openapi”,
“version”: “0.0.1”,
“private”: true,
“scripts”: {
“deploy”: “wrangler deploy”,
“dev”: “wrangler dev”,
“start”: “wrangler dev”,
“cf-typegen”: “wrangler types”
},
“dependencies”: {
“@cloudflare/itty-router-openapi”: “^1.0.1”,
“antibotbrowser”: “^1.0.5”
},
“devDependencies”: {
“@cloudflare/workers-types”: “^4.20240620.0”,
“@types/node”: “20.8.3”,
“@types/service-worker-mock”: “^2.0.1”,
“wrangler”: “^3.60.3”
}
}
# Error Log
F:projectsapiJavaScriptApi_testimdb-api>wrangler dev
⛅️ wrangler 3.62.0
Running custom build: npm run
Lifecycle scripts included in [email protected]:
start
wrangler dev
available via npm run-script
:
deploy
wrangler deploy
dev
wrangler dev
cf-typegen
wrangler types
▲ [WARNING] Enabling Wrangler compile-time Node.js compatibility polyfill mode for builtins and globals. This is experimental and has serious tradeoffs.
[wrangler:inf] Ready on http://127.0.0.1:8787
X [ERROR] Could not resolve “fs/promises”
../node_modules/@puppeteer/browsers/lib/esm/fileUtil.js:8:31:
8 │ import { mkdir, readdir } from 'fs/promises';
╵ ~~~~~~~~~~~~~
The package “fs/promises” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “platform: ‘node'” to do that, which will remove this error.
X [ERROR] Could not resolve “fs/promises”
../node_modules/@puppeteer/browsers/lib/esm/install.js:8:30:
8 │ import { mkdir, unlink } from 'fs/promises';
╵ ~~~~~~~~~~~~~
The package “fs/promises” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “platform: ‘node'” to do that, which will remove this error.
X [ERROR] Could not resolve “fs/promises”
../node_modules/cosmiconfig/dist/Explorer.js:7:43:
7 │ const promises_1 = __importDefault(require("fs/promises"));
╵ ~~~~~~~~~~~~~
The package “fs/promises” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “platform: ‘node'” to do that, which will remove this error.
X [ERROR] Could not resolve “fs/promises”
../node_modules/cosmiconfig/dist/loaders.js:9:27:
9 │ const promises_1 = require("fs/promises");
╵ ~~~~~~~~~~~~~
The package “fs/promises” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “platform: ‘node'” to do that, which will remove this error.
X [ERROR] Could not resolve “typescript”
../node_modules/cosmiconfig/dist/loaders.js:74:29:
74 │ typescript = require('typescript');
╵ ~~~~~~~~~~~~
You can mark the path “typescript” as external to exclude it from the bundle, which will remove this error. You can also surround this “require” call with a try/catch block to handle this failure at run-time instead of bundle-time.
X [ERROR] Could not resolve “typescript”
../node_modules/cosmiconfig/dist/loaders.js:103:35:
103 │ typescript = (await import('typescript')).default;
╵ ~~~~~~~~~~~~
You can mark the path “typescript” as external to exclude it from the bundle, which will remove this error. You can also add “.catch()” here to handle this failure at run-time instead of bundle-time.
X [ERROR] Could not resolve “fs/promises”
../node_modules/puppeteer-core/lib/esm/puppeteer/node/ChromeLauncher.js:6:24:
6 │ import { mkdtemp } from 'fs/promises';
╵ ~~~~~~~~~~~~~
The package “fs/promises” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “platform: ‘node'” to do that, which will remove this error.
X [ERROR] Could not resolve “fs/promises”
../node_modules/puppeteer-core/lib/esm/puppeteer/node/FirefoxLauncher.js:7:40:
7 │ import { rename, unlink, mkdtemp } from 'fs/promises';
╵ ~~~~~~~~~~~~~
The package “fs/promises” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “platform: ‘node'” to do that, which will remove this error.
X [ERROR] Could not resolve “http2”
node_modules/http2-wrapper/source/agent.js:4:22:
4 │ const http2 = require('http2');
╵ ~~~~~~~
The package “http2” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “platform: ‘node'” to do that, which will remove this error.
X [ERROR] Could not resolve “http2”
node_modules/http2-wrapper/source/client-request.js:2:22:
2 │ const http2 = require('http2');
╵ ~~~~~~~
The package “http2” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “platform: ‘node'” to do that, which will remove this error.
X [ERROR] Could not resolve “http2”
node_modules/http2-wrapper/source/index.js:2:22:
2 │ const http2 = require('http2');
╵ ~~~~~~~
The package “http2” wasn’t found on the file system but is built into node. Are you trying to bundle for node? You can use “platform: ‘node'” to do that, which will remove this error.
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮│ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit │╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
X [ERROR] Failed to build
???? Logs were written to “C:UsersManjunathSKAppDataRoamingxdg.config.wranglerlogswrangler-20 24-07-01_08-54-27_463.log”
1