Npm dependencies not deduplicated when using npm local paths

Hi Meteor gurus :wave:
We’ve found that npm dependencies are duplicated in our (production) bundle, probably caused by local paths imports

Tested on moment (cause it’s big :grin:), but it applies also to other packages.

Project structure (simplified):
/packages/utils – just javascript library, depends on moment, installed from npm, exactly the same version as in /app
/packages/app – Meteor app, depends on moment installed from npm and utils installed from file:../utils

I’ve checked the resulting bundle file, and moment is really twice there, so it’s not an error in bundle-visualizer.

Repo

Somebody struggled with this? Would appreciate any tips :slight_smile:

I’ve managed to (hot)fix it by changing

"dependencies": {
  "utils": "file:../utils"
  "moment": "2.29.1"
},

to

"dependencies": {
  "utils": "file:../utils"
  "moment": "file:../utils/node_modules/moment"
},

but it seems nasty to me, as I would hope that this deduplication would happen in bundler automatically :pray:

1 Like

I am also surprised by this - before you made this change did you have the same version of moment referenced in both places?

I just checked my build and moment is only added to bundle/programs/server/packages/mrt_moment.js and mrt_moment-timezone.js it’s just two files there’s nothing else for moment.

What’s your build looking like are you doing anything different in there? Moment is just a tiny file of a few thousand lines.

How are you including moment because in my build packages/utils and packages/app it doesnt get added and on the /bundle/programs/web.browser build it isn’t included.