Some packages from node_modules are missing from Ember registry in production mode

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.

1 Like

what dependencies are declared in your package.json? are you using embroider or the classic broccoli build?

I am not using embroider, I am using the old broccoli build system.

These are the dependencies:

  "dependencies": {
    "ember-cli-deploy": "^2.0.0",
    "ember-cli-deploy-build": "^3.0.0",
    "ember-cli-deploy-s3": "4.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.23.2",
    "@babel/eslint-parser": "^7.22.15",
    "@babel/plugin-proposal-decorators": "^7.23.2",
    "@ember/optional-features": "^2.0.0",
    "@ember/render-modifiers": "^2.1.0",
    "@ember/string": "^3.1.1",
    "@ember/test-helpers": "^3.2.0",
    "@glimmer/component": "^1.1.2",
    "@glimmer/tracking": "^1.1.2",
    "@stripe/stripe-js": "^3.1.0",
    "babel-eslint": "^8.2.6",
    "bootstrap": "^4.6.2",
    "broccoli-asset-rev": "^3.0.0",
    "broccoli-funnel": "^3.0.8",
    "broccoli-sass-source-maps": "4.2.1",
    "concurrently": "^8.2.2",
    "ember-auto-import": "^2.7.2",
    "ember-bootstrap": "^6.0.1",
    "ember-bootstrap-changeset-validations": "^5.0.0",
    "ember-changeset": "^4.1.2",
    "ember-changeset-validations": "^4.1.1",
    "ember-cli": "~5.4.0",
    "ember-cli-app-version": "^6.0.1",
    "ember-cli-autoprefixer": "^2.0.0",
    "ember-cli-babel": "^8.2.0",
    "ember-cli-clean-css": "^3.0.0",
    "ember-cli-dependency-checker": "^3.3.2",
    "ember-cli-htmlbars": "^6.3.0",
    "ember-cli-inject-live-reload": "^2.1.0",
    "ember-cli-sass": "^10.0.1",
    "ember-cli-sri": "^2.1.1",
    "ember-cli-terser": "^4.0.2",
    "ember-data": "~5.3.0",
    "ember-decorators": "^6.1.1",
    "ember-fetch": "^8.1.2",
    "ember-l10n": "git://github.com/Glamping-Hub/ember-l10n#579f87a9252814c119e5192d565d8bdd327a4198",
    "ember-load-initializers": "^2.1.2",
    "ember-modifier": "^4.1.0",
    "ember-moment": "^10.0.0",
    "ember-page-title": "^8.2.3",
    "ember-power-calendar": "^0.21.0",
    "ember-power-calendar-moment": "^0.4.0",
    "ember-qunit": "^8.0.1",
    "ember-radio-buttons": "^5.0.0",
    "ember-resolver": "^11.0.1",
    "ember-router-scroll": "^4.1.2",
    "ember-simple-auth": "^6.0.0",
    "gh-ember-simple-auth-token": "6.0.0-beta.1.2",
    "ember-source": "~5.4.0",
    "ember-template-lint": "^5.11.2",
    "ember-template-lint-plugin-prettier": "^5.0.0",
    "ember-truth-helpers": "^4.0.3",
    "eslint": "^8.52.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-ember": "^11.11.1",
    "eslint-plugin-n": "^16.2.0",
    "eslint-plugin-prettier": "^5.0.1",
    "eslint-plugin-qunit": "^8.0.1",
    "gettext-parser": "^7.0.1",
    "litepicker": "^1.5.7",
    "loader.js": "^4.7.0",
    "moment": "^2.30.1",
    "prettier": "^3.0.3",
    "qunit": "^2.20.0",
    "qunit-dom": "^2.0.0",
    "sass-embedded": "^1.67.0",
    "stylelint": "^15.11.0",
    "stylelint-config-standard": "^34.0.0",
    "stylelint-prettier": "^4.0.2",
    "webpack": "^5.89.0"
  },

There a couple of specific dependencies that are customized. ember-l10n points to a pull request to avoid using the old assign polyfill, it’s actually v5.2.0. And the ember-simple-auth-token is the new addon v2 that is in beta right now.

But I am convinced that those two are not the reason of the registry issue. I’ve tried it removing them and the result is the same.

this is super bizarre.

is this behavior reproducible in a vanilla / blank / new app?

I suspect those are all V2 addons, meaning they get handled by webpack.

Do you see a failing network request for a webpack chunk file? My guess would be that you have some combination of production fingerprinting settings that is breaking the webpack chunks. Check ember-auto-import’s publicAssetURL setting.

1 Like

You’re right @ef4, that is what’s happening:

Now I just need to figure out why those chunks are being blocked.

Thanks!

Found it, in one of the changes I made for the 5.4 update I added code around the publicAssetURL setting, and I covered the production environment case, but not our internal testing environment.

Webpack was trying to load the chunks from the wrong environment, that is why it wasn’t working.

Now it works perfectly.

Thank you everyone!

2 Likes