embroider-build / ember-auto-import

Zero config import from npm packages
Other
360 stars 109 forks source link

Uncaught Error: Could not find module `fast-memoize` #534

Closed tomcornelis closed 2 years ago

tomcornelis commented 2 years ago

I need to add ember-auto-import (as part of upgrading moment 2.24 to 2.29.4), but this seems to conflict with ember-intl (which already requires ember-auto-import) too and suddenly causes the following error (even though ember-intl worked fine before I've added ember-auto-import)

Uncaught Error: Could not find module `fast-memoize` imported from `ember-intl/-private/formatters/-format-datetime`

What could be the cause of this issue?

artemgurzhii commented 2 years ago

Having the same issue, my stack:

Ember: 3.28.9
Ember Data: 3.28.10
Ember Bootstrap: 5.1.1
ember-auto-import: 2.4.2
ember-intl: 5.7.2

everything works fine when running ember serve, the issue is present when running ember deploy production

artemgurzhii commented 2 years ago

@tomcornelis I found what is the issue, in my case fast-memoize is actually loaded,

I had such config:

autoImport: {
  forbidEval: true,
  publicAssetURL: '/assets',

  alias: {},

  exclude: [],
  insertScriptsAt: 'auto-import-scripts',
},

and such fingerprint

const fingerprint = IS_PROD
  ? {
      prepend: './',
      enabled: true,
      generateAssetMap: true,
    }
  : {};

changing from publicAssetURL: '/assets', to publicAssetURL: './assets', fixed the issue

P.S. General recommendation from the person who spend almost 3 hours trying to fix it, open the page, open its view-source, check if there are scripts loaded by the ember-auto-import, and check their code, if you have an error that's it can't find the module then play around with the publicAssetURL and other configs like prepend. Also, try to run locally ember deploy production, open the dist/index.html in the browser and start changing locally dist/index.html with the different paths for those scripts. Cheers!

ef4 commented 2 years ago

P.S. General recommendation...

Yes, do not fall into the trap of focussing attention only on the stack trace (which happens second) and ignoring the HTTP 404 for the script (which happens first). The first error error is the actual cause. The second error is a symptom of the first.

artemgurzhii commented 2 years ago

@ef4 I agree, and it would be great to document it somewhere, something like I have written above, but in a more smart/correct way

tomcornelis commented 2 years ago

@artemgurzhii Thanks for hinting me in the right direction.

In my case my ember app (through the vendor and app javascripts) was integrated in another other html page, instead of the standard app/index.html. Therefore I was able to solve it by also including the script tags for the dist/assets/chunk*.js in this custom html page.