Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Larger size of the generated worker with wrangler v1.9.x #1338

Closed
jorgelbg opened this issue May 28, 2020 · 18 comments
Closed

Larger size of the generated worker with wrangler v1.9.x #1338

jorgelbg opened this issue May 28, 2020 · 18 comments
Labels
bug Something isn't working webpack Issues that involve the `webpack` bundler

Comments

@jorgelbg
Copy link

🐛 Bug Report

Environment

  • operating system: macOS 10.15.4
  • output of rustc -V: rustc 1.43.1
  • output of node -v: v14.3.0
  • output of wrangler -V: wrangler 1.9.2
  • contents of wrangler.toml:
name = "log-shipper"
type = "webpack"
account_id = "xxxxx"
workers_dev = true
route = ""
zone_id = "xxxxx"
webpack_config = "webpack.config.js"

[env.dev]
webpack_config = "webpack.dev.config.js"

Steps to reproduce

When building the project using wrangler v1.8 the size of the worker is 635Kib:

❯❯❯ npm install -g @cloudflare/[email protected]                                                         23:23:18
/usr/local/bin/wrangler -> /usr/local/lib/node_modules/@cloudflare/wrangler/run-wrangler.js

> @cloudflare/[email protected] postinstall /usr/local/lib/node_modules/@cloudflare/wrangler
> node ./install-wrangler.js

Downloading release https://workers.cloudflare.com/get-npm-wrangler-binary/1.8.4/x86_64-apple-darwin
wrangler has been installed!
+ @cloudflare/[email protected]
updated 3 packages in 3.694s

~/C/worker master
❯❯❯ wrangler build                                                                                  23:23:23
⬇️ Installing wranglerjs...
⬇️ Installing wasm-pack...
Warning: webpack's output filename is being renamed to worker.js because of requirements from the Workers runtime
✨  Built successfully, built project size is 635 KiB.

After upgrading to v1.9 it goes over the 1Mb limit:

~/C/worker master 7s
❯❯❯ npm install -g @cloudflare/[email protected]                                                         23:23:38
/usr/local/bin/wrangler -> /usr/local/lib/node_modules/@cloudflare/wrangler/run-wrangler.js

> @cloudflare/[email protected] postinstall /usr/local/lib/node_modules/@cloudflare/wrangler
> node ./install-wrangler.js

Downloading release https://workers.cloudflare.com/get-npm-wrangler-binary/1.9.2/x86_64-apple-darwin
wrangler has been installed!
+ @cloudflare/[email protected]
updated 3 packages in 4.24s

~/C/worker master 6s
❯❯❯ wrangler build                                                                     23:25:42
Warning: webpack's output filename is being renamed to worker.js because of requirements from the Workers runtime
✨  Built successfully, built project size is 1 MiB. ⚠️  Your built project has grown past the 1MiB size limit and may fail to deploy. ⚠️

~/C/worker master 9s
❯❯❯ wrangler --version                                                                              23:26:29
👷 ✨  wrangler 1.9.2

This larger size is also confirmed when trying to publish the worker:

❯❯❯ wrangler publish                                                                                23:54:11
Warning: webpack's output filename is being renamed to worker.js because of requirements from the Workers runtime
✨  Built successfully, built project size is 1 MiB. ⚠️  Your built project has grown past the 1MiB size limit and may fail to deploy. ⚠️
Error: Something went wrong! Status: 400 Bad Request, Details {
  "result": null,
  "success": false,
  "errors": [
    {
      "code": 10027,
      "message": "workers.api.error.script_too_large"
    }
  ],
  "messages": []
}

What did you expect to see?

Same size of the worker for the different versions of wrangler.

What did you see instead?

The size of the worker should not be different between wrangler versions.

I noticed this issue after upgrading to wrangler v1.9.0 #1188 (comment) but now I confirmed that the same thing is happening after using the latest release v1.9.2.

@EverlastingBugstopper
Copy link
Contributor

Hey @jorgelbg - this seems like a bug but it's hard to know what's happening without a repo that can reliably reproduce the error.

Could you make an example repository or link the repository you're using so we can attempt to reproduce the different behavior between 1.8 and 1.9? Thanks!

@jorgelbg
Copy link
Author

jorgelbg commented Jun 2, 2020

@EverlastingBugstopper here is the repository where I've seen the issue https://github.com/jorgelbg/loki-log-shipper.

BTW Thanks for the template 😄.

@EverlastingBugstopper
Copy link
Contributor

If I run wrangler build with wrangler 1.8.4 on that repository, I get the same message about size.

$ wrangler --version
👷 ✨  wrangler 1.8.4    
$ wrangler build    

> [email protected] install ~/dir/loki-log-shipper/node_modules/fsevents
> node-gyp rebuild

  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node
npm WARN [email protected] No repository field.

added 614 packages from 905 contributors and audited 615 packages in 18.146s

16 packages are looking for funding
  run `npm fund` for details

found 19 vulnerabilities (16 low, 3 moderate)
  run `npm audit fix` to fix them, or `npm audit` for details
⬇️ Installing wranglerjs...
⬇️ Installing wasm-pack...
Warning: webpack's output filename is being renamed to worker.js because of requirements from the Workers runtime
✨  Built successfully, built project size is 1 MiB. ⚠️  Your built project has grown past the 1MiB size limit and may fail to deploy. ⚠️ 

@EverlastingBugstopper
Copy link
Contributor

that being said - if you remove devtool: 'source-map' from your custom webpack.config.js, the size should be much smaller (that's my bad, it's in my template, i'll submit a pr to fix that)

@jorgelbg
Copy link
Author

jorgelbg commented Jun 2, 2020

🤔 I've even cloned the repository into a different path and run with 1.8.4 and I don't get the error, I do get it with 1.9.2.

Indeed removing the source maps trims down the size, but I was more puzzled about the difference in size between the 2 versions without any other changes.

@jorgelbg
Copy link
Author

jorgelbg commented Jun 2, 2020

Tried again now and this is the console output of the entire clone/build process: https://gist.github.com/jorgelbg/734a401858bdae18275276180bc76741

@EverlastingBugstopper
Copy link
Contributor

hmmmmmm - i cannot reproduce this for the life of me. perhaps @ashleymichal can take a look? super strange for sure...

as for the template, i've updated it to not include source maps: https://github.com/EverlastingBugstopper/worker-typescript-template/compare/972ddb6..aa7435c

@jorgelbg
Copy link
Author

jorgelbg commented Jun 3, 2020

To make things even more strange, after removing the source maps, I still see a difference in the project size between v1.8 and v1.9:

v1.8.4:

✨  Built successfully, built project size is 181 KiB.

v1.9.2:

✨  Built successfully, built project size is 275 KiB.

@ashleymichal ashleymichal removed this from the 1.10.0 milestone Jun 5, 2020
@adaptive
Copy link
Contributor

One important note, the value derives from webpack. The uncompressed id 885 KiB (compressed 275 KiB). @jorgelbg can you check the uncompressed of the other versions?

v1.10.1:
✨ Built successfully, built project size is 275 KiB.

@jorgelbg
Copy link
Author

  • v1.8.4: 522.4 KB
  • v1.9.4: 885.9 KB
  • v1.10.1: 886 KB

@adaptive Sizes between v1.9.x and v1.10.x are somehow similar but still larger than v.1.8.4.

@stale
Copy link

stale bot commented Aug 16, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Aug 16, 2020
@stale
Copy link

stale bot commented Aug 23, 2020

This issue has been automatically closed because it has not had recent activity. You may re-open the issue if it is still relevant.

@stale stale bot closed this as completed Aug 23, 2020
@yerol
Copy link

yerol commented Sep 18, 2020

I'm having this exact problem.

The same project/code, builds and packages to 206KB with wrangler 1.6, but jumps to 377KB when I upgrade wrangler to 1.11. This is the same on windows and mac. This jump in size is unacceptable for a platform like this.

I'll be sticking with old versions of wrangler until this issues is sorted out.

Attached screenshot:
Screenshot_1

@ispivey ispivey removed the wontfix label Sep 18, 2020
@ashleymichal ashleymichal reopened this Sep 18, 2020
@yerol
Copy link

yerol commented Sep 24, 2020

I think I've found the underlying problem. It's dependency duplication. In the bundled worker.js file, I have the same package (bn.js) included 8 times! It is highly likely that there are other packages duplicated as well. See below references:

// "../../../../AppData/Local/.wrangler/wranglerjs-1.11.0/node_modules/asn1.js/node_modules/bn.js/lib/bn.js":
/
/ "../../../../AppData/Local/.wrangler/wranglerjs-1.11.0/node_modules/bn.js/lib/bn.js":
// "../../../../AppData/Local/.wrangler/wranglerjs-1.11.0/node_modules/browserify-rsa/node_modules/bn.js/lib/bn.js":
/
/ "../../../../AppData/Local/.wrangler/wranglerjs-1.11.0/node_modules/create-ecdh/node_modules/bn.js/lib/bn.js":
// "../../../../AppData/Local/.wrangler/wranglerjs-1.11.0/node_modules/diffie-hellman/node_modules/bn.js/lib/bn.js":
/
/ "../../../../AppData/Local/.wrangler/wranglerjs-1.11.0/node_modules/elliptic/node_modules/bn.js/lib/bn.js":
// "../../../../AppData/Local/.wrangler/wranglerjs-1.11.0/node_modules/miller-rabin/node_modules/bn.js/lib/bn.js":
/
/ "../../../../AppData/Local/.wrangler/wranglerjs-1.11.0/node_modules/public-encrypt/node_modules/bn.js/lib/bn.js":

@yerol
Copy link

yerol commented Dec 10, 2020

Just to confirm, this is still an issue with version 1.12.2. With a minified production build, there is a difference of around 90kb compared to version 1.6. This difference does not seem to change with the amount of (user) code in the worker. This is all due to different version references of BN.js and couple of other duplicated dependencies in the core. In version 1.6, the bundle contains only one version of those dependencies hence a lot smaller in size.

@Electroid Electroid added webpack Issues that involve the `webpack` bundler and removed investigate user report labels Feb 22, 2021
@Electroid Electroid added the bug Something isn't working label Mar 18, 2021
@Electroid
Copy link
Contributor

Just wanted to give an update here, we're introducing custom builds as part of #1818. After that merges, if you use custom builds, this will not longer be an issue.

@yerol
Copy link

yerol commented Mar 18, 2021

This sounds great. Please let us know when this is merged and I'll test again. Thanks.

@Electroid
Copy link
Contributor

This should actually be fixed in #1722

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working webpack Issues that involve the `webpack` bundler
Projects
None yet
Development

No branches or pull requests

7 participants