What i did:
Created the worker on the web ui and initialized locally with wrangler init --from-dash
I installed twilio with npm i twilio
,
This is the code im trying to run (index.js)
export default {
async fetch(request, ctx) {
const accountSid = "<>";
const authToken = "<>";
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
from: 'whatsapp:<>',
body: 'Hello there finally!',
to: 'whatsapp:<>'
});
return new Response("test");
},
};
when I run npm start, i get the following errors
✘ [ERROR] Could not resolve "events"
node_modules/agent-base/dist/src/index.js:5:25:
5 │ const events_1 = require("events");
╵ ~~~~~~~~
The package "events" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "buffer"
node_modules/buffer-equal-constant-time/index.js:3:21:
3 │ var Buffer = require('buffer').Buffer; // browserify
╵ ~~~~~~~~
The package "buffer" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "net"
node_modules/https-proxy-agent/dist/agent.js:15:38:
15 │ const net_1 = __importDefault(require("net"));
╵ ~~~~~
The package "net" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "tls"
node_modules/https-proxy-agent/dist/agent.js:16:38:
16 │ const tls_1 = __importDefault(require("tls"));
╵ ~~~~~
The package "tls" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "url"
node_modules/https-proxy-agent/dist/agent.js:17:38:
17 │ const url_1 = __importDefault(require("url"));
╵ ~~~~~
The package "url" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "assert"
node_modules/https-proxy-agent/dist/agent.js:18:41:
18 │ const assert_1 = __importDefault(require("assert"));
╵ ~~~~~~~~
The package "assert" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "crypto"
node_modules/jsonwebtoken/sign.js:12:65:
12 │ ...KeyObject, createSecretKey, createPrivateKey } = require('crypto')
╵ ~~~~~~~~
The package "crypto" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "crypto"
node_modules/jsonwebtoken/verify.js:9:62:
9 │ ... {KeyObject, createSecretKey, createPublicKey} = require("crypto");
╵ ~~~~~~~~
The package "crypto" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "crypto"
node_modules/jwa/index.js:3:21:
3 │ var crypto = require('crypto');
╵ ~~~~~~~~
The package "crypto" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "util"
node_modules/jwa/index.js:5:19:
5 │ var util = require('util');
╵ ~~~~~~
The package "util" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "stream"
node_modules/jws/lib/data-stream.js:3:21:
3 │ var Stream = require('stream');
╵ ~~~~~~~~
The package "stream" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
✘ [ERROR] Could not resolve "util"
node_modules/jws/lib/data-stream.js:4:19:
4 │ var util = require('util');
╵ ~~~~~~
The package "util" wasn't found on the file system but is built into node.
Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
node version - v20.11.0
npm version - 10.2.4
(installed node js using the tar from the official website)
OS - pop os 21.04