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
Do you have a link to your repo?
yes, it's in the issue
Oops, sorry, missed that...
np
project hasn't been touched for 2 years, hence I'm upgrading to latest wrangler etc. and ran into this problem
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.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.the plugins shouldn't matter at all - webpack just turns them into strings
One of them compiles Sass to CSS and the other syntax-highlights markdown files, no?
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-parserwhich is a dependency of typescript itself!!! are you suggesting I can't use typescript?
GitHub
TypeScript/package.json at 7c417bfd1d14326575a2f08f8b6013a8c10d9f9e...
TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - microsoft/TypeScript
I'll also note that if remove the loads for scss and markdown, I still get that error
Sorry, I didn't mean that they were causing the error
@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 typescriptI 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...
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?
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.
that's fine, can you point to instructions?
That's what I mean. Since there aren't any instructions, you would have to bodge your way through yourself.
is there an example somewhere?
Not that I know of, though there might be some on Github
😞
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.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 lotHere's a really basic webpack config we use to build a worker with an older project, without the compat plugin:
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:
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 🙂Your node version is way too old for modern tooling. You need to upgrade to at least node 16