I have a project that I am updating from Ember 3.28 to Ember 5.4. After a lot of updating everything works perfectly in development, the app runs well and there are no errors. But it doesn’t load when opening it in production mode.
I get this error:
Uncaught Error: Could not find module `ember-simple-auth/initializers/ember-simple-auth` imported from `dashboard/initializers/ember-simple-auth`
It complains that it can’t load the ember-simple-auth
module (I’m installing version 6.0.0 of that addon).
After investigating a debugging I’ve finally ended up checking the Ember modules registry. I think that is a part of Ember-CLI loader.js.
For some unknown reason, there are several packages that in development mode are being processed by the define method of the loader, but they are not in production. The define
method is what includes items in the registry, one per each module available. Later when requiring models, Ember checks that registry. The registry is basically a dictionary with the modules names.
So I have checked the difference in the Object.keys
values between the registry in development mode, and in production mode.
- For development I run:
ember serve
- For production I run:
ember serve -prod
And this is the list of packages missing in the registry in production mode:
"@popperjs/core",
"@stripe/stripe-js/pure",
"ember-cookies/services/cookies",
"ember-element-helper/helpers/element",
"ember-focus-trap/modifiers/focus-trap.js",
"ember-modifier",
"ember-moment/helpers/-base.js",
"ember-moment/helpers/is-after.js",
"ember-moment/helpers/is-before.js",
"ember-moment/helpers/is-between.js",
"ember-moment/helpers/is-same-or-after.js",
"ember-moment/helpers/is-same-or-before.js",
"ember-moment/helpers/is-same.js",
"ember-moment/helpers/moment-add.js",
"ember-moment/helpers/moment-calendar.js",
"ember-moment/helpers/moment-diff.js",
"ember-moment/helpers/moment-duration.js",
"ember-moment/helpers/moment-format.js",
"ember-moment/helpers/moment-from-now.js",
"ember-moment/helpers/moment-from.js",
"ember-moment/helpers/moment-subtract.js",
"ember-moment/helpers/moment-to-date.js",
"ember-moment/helpers/moment-to-now.js",
"ember-moment/helpers/moment-to.js",
"ember-moment/helpers/moment.js",
"ember-moment/helpers/now.js",
"ember-moment/helpers/unix.js",
"ember-moment/helpers/utc.js",
"ember-moment/services/moment.js",
"ember-page-title/helpers/page-title",
"ember-page-title/services/page-title",
"ember-simple-auth/initializers/ember-simple-auth",
"ember-simple-auth/services/session",
"ember-simple-auth/session-stores/application",
"ember-simple-auth/utils/inject",
"ember-simple-auth/utils/is-fastboot",
"ember-simple-auth/utils/location",
"ember-simple-auth/utils/objects-are-equal",
"ember-style-modifier/modifiers/style",
"ember-truth-helpers/helpers/and",
"ember-truth-helpers/helpers/eq",
"ember-truth-helpers/helpers/gt",
"ember-truth-helpers/helpers/gte",
"ember-truth-helpers/helpers/is-array",
"ember-truth-helpers/helpers/is-empty",
"ember-truth-helpers/helpers/is-equal",
"ember-truth-helpers/helpers/lt",
"ember-truth-helpers/helpers/lte",
"ember-truth-helpers/helpers/not",
"ember-truth-helpers/helpers/not-eq",
"ember-truth-helpers/helpers/or",
"ember-truth-helpers/helpers/xor",
"gh-ember-simple-auth-token/authenticators/jwt",
"gh-ember-simple-auth-token/initializers/simple-auth-token",
"validated-changeset",
There are also some more missing from ember-testing
, but I guess that makes sense for production mode.
I have no idea why the previous list of modules are not being loaded into the registry when adding the -prod
flag (same when using build
). I’ve run the ember-auto-import
and the webpack
with the verbose flags, but I haven’t seen anything useful in the log.
I’ve also tried many different versions of the packages from that list, but nothing. Same result always.
Any ideas why some packages could be treated differently by the auto import / loader / webpack tools in production mode?
Thank you.