wrangler and webpack

I'm having issues trying to use wrangler 3 with webpack - the issue is described here - https://github.com/cloudflare/workers-sdk/issues/3764, but no reply for two weeks. Help would be much appreciated. I'm effectively blocked from moving forward by this.
GitHub
Issues · cloudflare/workers-sdk
⛅️ Home to Wrangler, the CLI for Cloudflare Workers® - Issues · cloudflare/workers-sdk
27 Replies
Hello, I’m Allie!
Do you have a link to your repo?
samuelcolvin
samuelcolvin10mo ago
yes, it's in the issue
Hello, I’m Allie!
Oops, sorry, missed that...
samuelcolvin
samuelcolvin10mo ago
np project hasn't been touched for 2 years, hence I'm upgrading to latest wrangler etc. and ran into this problem
Hello, I’m Allie!
Hm, you might need to rebuild at least part of it. While it might work if you just deployed it with wrangler@1 now, it looks like a lot of the plugins that you use don't directly translate over.
Hello, I’m Allie!
I'd note too that the issue seems to be arising from a dependency, jsonc-parser
npm
jsonc-parser
Scanner and parser for JSON with comments.. Latest version: 3.2.0, last published: a year ago. Start using jsonc-parser in your project by running npm i jsonc-parser. There are 513 other projects in the npm registry using jsonc-parser.
samuelcolvin
samuelcolvin10mo ago
the plugins shouldn't matter at all - webpack just turns them into strings
Hello, I’m Allie!
One of them compiles Sass to CSS and the other syntax-highlights markdown files, no?
samuelcolvin
samuelcolvin10mo ago
yes, both of which becomes strings - that's what webpack does
I'd note too that the issue seems to be arising from a dependency, jsonc-parser
which is a dependency of typescript itself!!! are you suggesting I can't use typescript?
samuelcolvin
samuelcolvin10mo ago
I'll also note that if remove the loads for scss and markdown, I still get that error
Hello, I’m Allie!
Sorry, I didn't mean that they were causing the error
samuelcolvin
samuelcolvin10mo ago
@HardAtWork it might help if you try to build a minimal project with wranglerjs-compat-webpack-plugin - I think you'll get the same error provided you use typescript
Hello, I’m Allie!
I was just trying to say that because the guide involves upgrading to v2(and the current version is v3), I'm not sure it is compatible, so I was trying to find a way for you to migrate away from using webpack entirely...
samuelcolvin
samuelcolvin10mo ago
yes, I see that, but I need webpack as you can see - precisely because I need those files does that mean there's no way to use webpack with wrangler 3?
Hello, I’m Allie!
There is, but as far as I know, it isn't an officially supported thing, so you would probably have to manage the build yourself.
samuelcolvin
samuelcolvin10mo ago
that's fine, can you point to instructions?
Hello, I’m Allie!
That's what I mean. Since there aren't any instructions, you would have to bodge your way through yourself.
samuelcolvin
samuelcolvin10mo ago
is there an example somewhere?
Hello, I’m Allie!
Not that I know of, though there might be some on Github
samuelcolvin
samuelcolvin10mo ago
😞
Hello, I’m Allie!
Though I would note too that while you do use webpack for Sass compilation and Markdown Highlighting, it shouldn't be too difficult to find esbuild plugins that do the same Which is generally more supported.
samuelcolvin
samuelcolvin10mo ago
makes sense thanks for the input it would be great if someone could update the docs to note that wranglerjs-compat-webpack-plugin doesn't work with wrangler v3, and reply to the issue too this kind of thing would improve DX a lot
James
James10mo ago
Here's a really basic webpack config we use to build a worker with an older project, without the compat plugin:
require('dotenv').config();

const path = require('path');

const webpack = require('webpack');
let devMode = process.env.NODE_ENV !== 'production';

module.exports = function(mode) {
if(mode === 'production') {
devMode = false;
}
if(mode === 'development') {
devMode = true;
}
const config = {
target: 'webworker',
devtool: false,
entry: './src/worker/index.js',
output: {
path: path.resolve(__dirname, 'src/worker/dist'),
filename: 'worker.js',
},
mode: 'production',
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
},
},
],
},
plugins: [],
};
if(devMode) {
// stuff?
}
return config;
};
require('dotenv').config();

const path = require('path');

const webpack = require('webpack');
let devMode = process.env.NODE_ENV !== 'production';

module.exports = function(mode) {
if(mode === 'production') {
devMode = false;
}
if(mode === 'development') {
devMode = true;
}
const config = {
target: 'webworker',
devtool: false,
entry: './src/worker/index.js',
output: {
path: path.resolve(__dirname, 'src/worker/dist'),
filename: 'worker.js',
},
mode: 'production',
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
},
},
],
},
plugins: [],
};
if(devMode) {
// stuff?
}
return config;
};
Which is then invoked with cross-env NODE_ENV=production webpack --progress --mode=production --env production -c webpack.worker.config.js, and wrangler.toml has:
main = "./src/worker/dist/worker.js"
main = "./src/worker/dist/worker.js"
It's an older project so I've not refactored it to esbuild or something more modern, but if you really want to use webpack, a config like that should get you started 🙂
Laputa
Laputa10mo ago
No description
James
James10mo ago
Your node version is way too old for modern tooling. You need to upgrade to at least node 16
Want results from more Discord servers?
Add your server
More Posts
also does cloudflare r2 store my data inalso, does cloudflare r2 store my data in multiple regions? (i don't refer to caching, i mean a backCloudFlare WARP VPN not workingCloud-flare WARP VPN not working i keep getting "Connecting" then I get "Disconnecting" " Your conneI already try then cursor freezes and noI already try then cursor freezes and no progress to show ,in cloudflare same storage usedService workers binding limitHey all, is there a limit on the number of service workers bindings a worker can have?Need Help with Cloudflare DNS Configuration for Custom Domain with github.Hello everyone, I hope you're doing well. I'm currently facing an issue with setting up my custom dCan't deploy changes – environment exists but "not found"When I try to deploy a script using: npx wrangler deploy --env foo I get the following error: A reqI'm facing some issue when using middleware in `/functions`. Can someone help?I am using middleware in `/functions` to secure some pages. But when the url has double slashes `//`Can't connect to QUIC after enabling permanent mode on OVH FirewallCloudflared is unable to connect to Cloudflare Network with `quic` protocol, then most likely your mTransfering 600k images from google cloud storage to cloudflare imagesI have just signed up for cloudflares creator bundle for images. I have around 600k of images on gcpWAF on non-known bots trigger on a web browser GET requestWhile playing around with Cloudflare security rules for R2, I came across the `Known Bots` flag. I'