Starting out with workers and bundling code

Hello, we are trying to build a worker using hono and sequelize. It's basically an API that we will call from various locations, to do CRUD ops into a database (aws aurora mysql currently). Any pointers on how to bundle the code? I've tried to set `type = "webpack" in wrangler.toml but seems like it's deprecated? Thanks
15 Replies
Hello, I’m Allie!
wrangler can automatically bundle your code for you. Set your main field to your entrypoint(src/index.ts/js), and it should auto-bundle it.
stavros-k
stavros-kOP3y ago
I do have this set, but for example I get errors like this:
✘ [ERROR] Could not resolve "url"

node_modules/pg-connection-string/index.js:3:18:
3 │ var url = 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 to enable Node compatibility.


✘ [ERROR] Could not resolve "fs"

node_modules/pg-connection-string/index.js:4:17:
4 │ var fs = require('fs')
╵ ~~~~
✘ [ERROR] Could not resolve "url"

node_modules/pg-connection-string/index.js:3:18:
3 │ var url = 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 to enable Node compatibility.


✘ [ERROR] Could not resolve "fs"

node_modules/pg-connection-string/index.js:4:17:
4 │ var fs = require('fs')
╵ ~~~~
setting node_compat brings a whole lot of other errors
Hello, I’m Allie!
Looks like sequelize isn't compatible with Workers. node_compat can fix some of those issues, but if it requires access to a file system, then it won't work.
stavros-k
stavros-kOP3y ago
Hmm any ideas of a package for mysql db's that is compatible?
stavros-k
stavros-kOP3y ago
Hmm I'll take a look into them! From a quick look, looks like they are some kind of proxy that you have to pay? Or is just a service that is "also" offered?
Hello, I’m Allie!
Prisma comes with Data Proxy usage of 3 million CPU ms/mo, and Planetscale is a Hosted MySQL-compatible database with the following Free Tier:
stavros-k
stavros-kOP3y ago
Seems a bit weird to pay for CF workers and then also pay for another proxy in to access a database that we also pay 🙂
Hello, I’m Allie!
There is also a tutorial to use CF Tunnels for DB Connectivity, but not 100% sure how well it is maintained. The main thing though is that DBs are made with long-running connections in mind, and thus aren't really architectures for short-lived connections with one or two transactions.
stavros-k
stavros-kOP3y ago
Not sure how tunnel will work with an aurora db in aws :/
Hello, I’m Allie!
There are some that are built from the ground up to be made for serverless workloads(Planetscale, Upscale, etc.), but those aren't just hosted MySQL/Postrgres
Hello, I’m Allie!
Using the Data API for Aurora Serverless v1 - Amazon Aurora
By using the Data API for Aurora Serverless v1 , you can work with a web-services interface to your Aurora Serverless v1 DB cluster. The Data API doesn't require a persistent connection to the DB cluster. Instead, it provides a secure HTTP endpoint and integration with AWS SDKs. You can use the endpoint to run SQL statements without managing con...
stavros-k
stavros-kOP3y ago
I see, maybe I'll check if aws have some sort of package/api for its db you beat me to it lol
Hello, I’m Allie!
I don't work with AWS very often, but it looks like this might work?
stavros-k
stavros-kOP3y ago
I'll give it a shot. It's the only thing that I plan to leave to AWS for now. DNS is already migrating to CF and some of the websites

Did you find this page helpful?