Moment-timezone: Error: Cannot find module 'moment'

Created on 18 Jun 2018  ·  8Comments  ·  Source: moment/moment-timezone

Node 6.11.1
Elastic Beanstalk Node.js running on 64bit Amazon Linux/4.2.1

Our microservices started failing a few moments ago when creating new instances of the nodejs app.

Error: use-plugin: Could not load plugin /var/app/current/src/xxxx defined in /var/app/current/src/xxxx as a require call inside the plugin (or a module required by the plugin) failed: Error: Cannot find module 'moment' at require (internal/module.js:20:19) at VERSION (/var/app/current/node_modules/moment-timezone/moment-timezone.js:12:28) at Object.<anonymous> (/var/app/current/node_modules/moment-timezone/moment-timezone.js:17:2) at require (internal/module.js:20:19) at Object.<anonymous> (/var/app/current/node_modules/moment-timezone/index.js:1:93).

I belive this is because of the latest 0.5.18 publish

Our current workaround is to use strict version in our package.json

"moment-timezone": "^0.5.14",

into

"moment-timezone": "0.5.14",

so the servers will pull strictly that version. I do not know if 0.5.17 works, as these are the ones in our package.json. I still have to update all our production repos, so I don't have time now to test.

edits

  • one thing we also did was to manuall install --save moment, so I'm not sure if the fix was making the version strict or the manual addition of moment main into package.json
  • if this was intentional, you might want to bump major version as this is a breaking change

Most helpful comment

@rpellerin I think it should be released as moment-timezone 0.6.0

All 8 comments

Hi @dragonjet I rolled back change which was done today, until we find out why it's breaking things.
peerDependency should be installed if it's not present, so it's strange that moment.js is not found.
You can definitely use moment-timezone 0.5.17 and 0.5.19

thanks :+1:
we'll update our packages to 0.5.17 for now, and will add moment to all repos, just in case :)

edit: i saw that new npm installs already pull 0.5.19, so I don't need to update all our repos anymore. thanks for the fast fix :1st_place_medal:

peer dependencies are no longer automatically downloaded, since npm 3 (source).
However, having moment declared as a peer dependency offers much more flexibility and allow bundles to be more lightweight, as it prevents from having several versions of moment installed.

Hi @ellenaua any chance we put moment back in the peerDependencies?

@rpellerin I think it should be released as moment-timezone 0.6.0

@ellenaua moment as peerDependencies is a good practice for, as @rpellerin said, bundle size and avoid errors with several versions of moment loaded.

I didn't mention it in my PR but it was indeed a breaking change.

Can you release it as 0.6.0 please?

Thanks!

It's happening on latest version of moment(v2.22.2) and moment-timezone(v0.5.21).

It took a lot of my time to figure out why my app keeps failing because of moment.tz was not defined. And it might be take lots of other people's time if someone just create a new project with latest versions installed, they should have this problem too.

Looking forward to release of 0.6.0 😃

----Update on 2018.10.6----
I'm using these versions in my project:

  "moment": “2.20.1"
  "moment-timezone": “0.5.21”

After almost a year, can we have a version of moment-timezone with moment as a peer dependency?

Was this page helpful?
0 / 5 - 0 ratings