Ionic 8 Angular 18: "The above dynamic import cannot be analyzed by Vite."

Upgrading to Angular 18 and still using:
"builder": "@angular-devkit/build-angular:application"

and I’m getting a vite warning on the Ionic internals:

730|      return i[n];
731|    }
732|    return import("./".concat(a, ".entry.js").concat("")).then(function(e2) {
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
733|      {
734|        cmpModules.set(a, e2);
The above dynamic import cannot be analyzed by Vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

  Plugin: vite:import-analysis
  File: /Users/saschwarz/dev/acmaster-upgrade/agility-course-master/.angular/cache/18.0.7/vite/deps/chunk-THRW7OZV.js?v=60485708

Looking in the file it is coming from ionic/core:

// node_modules/@ionic/core/dist/esm-es5/index-7a952e7a.js
var NAMESPACE = "ionic";
var BUILD = { allRenderFn: false, appendChildSlotFix: true, asyncLoading: true, asyncQueue: false, attachStyles: true, cloneNodeFix: true, cmpDidLoad: true, cmpDidRender: true, cmpDidUnload: false, cmpDidUpdate: true, cmpShouldUpdate: false, cmpWillLoad: true, cmpWillRender: true, cmpWillUpdate: false, connectedCallback: true, constructableCSS: true, cssAnnotations: true, devTools: false, disconnectedCallback: true, element: false, event: true, experimentalScopedSlotChanges: true, experimentalSlotFixes: true, formAssociated: false, hasRenderFn: true, hostListener: true, hostListenerTarget: true, hostListenerTargetBody: true, hostListenerTargetDocument: true, hostListenerTargetParent: false, hostListenerTargetWindow: true, hotModuleReplacement: false, hydrateClientSide: true, hydrateServerSide: false, hydratedAttribute: false, hydratedClass: true, hydratedSelectorName: "hydrated", initializeNextTick: false, invisiblePrehydration: true, isDebug: false, isDev: false, isTesting: false, lazyLoad: true, lifecycle: true, lifecycleDOMEvents: false, member: true, method: true, mode: true, observeAttribute: true, profile: false, prop: true, propBoolean: true, propMutable: true, propNumber: true, propString: true, reflect: true, scoped: true, scopedSlotTextContentFix: true, scriptDataOpts: false, shadowDelegatesFocus: true, shadowDom: true, slot: true, slotChildNodesFix: true, slotRelocation: true, state: true, style: true, svg: true, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: true, vdomKey: true, vdomListener: true, vdomPropOrAttr: true, vdomRef: true, vdomRender: true, vdomStyle: true, vdomText: true, vdomXlink: true, watchCallback: true };
var __defProp = Object.defineProperty;
var __export = function(e, t) {
  for (var r in t)
    __defProp(e, r, { get: t[r], enumerable: true });
};
var hostRefs = /* @__PURE__ */ new WeakMap();
var getHostRef = function(e) {
  return hostRefs.get(e);
};
var registerHost = function(e, t) {
  var r = { i: 0, $hostElement$: e, o: t, l: /* @__PURE__ */ new Map() };
  {
    r.u = new Promise(function(e2) {
      return r.v = e2;
    });
  }
  {
    r.p = new Promise(function(e2) {
      return r.h = e2;
    });
    e["s-p"] = [];
    e["s-rc"] = [];
  }
  return hostRefs.set(e, r);
};
var isMemberInElement = function(e, t) {
  return t in e;
};
var consoleError = function(e, t) {
  return (0, console.error)(e, t);
};
var cmpModules = /* @__PURE__ */ new Map();
var loadModule = function(e, t, r) {
  var n = e.m.replace(/-/g, "_");
  var a = e.S;
  if (!a) {
    return void 0;
  }
  var i = cmpModules.get(a);
  if (i) {
    return i[n];
  }
  return import("./".concat(a, ".entry.js").concat("")).then(function(e2) {
    {
      cmpModules.set(a, e2);
    }
    return e2[n];
  }, consoleError);
};

Is this warning expected?

1 Like

This was resolved by rm -rf .angular node_modules and then npm install

This did not fix it for me. When I restarted my app, it appeared after interacting with the app for 2 minutes again, in the run terminal. So it only made it disappear from the app start for a moment.

what’s your vite version? there have been some problems on recent vite versions, Ionic apps are created with version 5.2.0 pinned to prevent the errors caused by other newer versions

npm list vite

└─┬ @angular-devkit/build-angular@17.3.8
├─┬ @vitejs/plugin-basic-ssl@1.1.0
│ └── vite@5.1.7 deduped
└── vite@5.1.7

Hi guys,

I’m also currently experiencing this issue. Any updates on how to resolve this issue?

Thanks

my code runs fine with the issue. Is it pressing for you?

I’m also facing the same issue. Any updates on how to fix this?

same here. issue arise after updating builder to ESBuild.

Also experiencing this issue. I did remove .angular and node_modules, redid npm install and still got the issue.

I found the problem, the line that was giving problems was in my main.ts in the part of: providers: [importProvidersFrom(IonicModule.forRoot({ mode: ‘ios’ })),]
I replaced it with provideIonicAngular({ mode: ‘ios’ }), and in general you should remove any call to IonicModule and start using standalone!

I already had provideIonicAngular() in my main.ts when I encountered this issue, so it seems this may not be the solution for everybody.

Try to find if you have any call to ionicModule or any component that you use that is only calling @ionic/angular and not @ionic/angular/standalone, for example I had the modals imported not as standalone and that was causing it to fail.

1 Like

You’re right. That was the issue! Thanks man.

Ionic 8.4.1 and Angular 19 also have the same issue

1 Like

I don’t have this problem now

How did you resolve it?

Just managed to fix it in my app here… I discovered the following accidental import:

import { Platform } from '@ionic/angular';

Changed it to the following, and the problem went away:

import { Platform } from '@ionic/angular/common';

So apparently, you need to be diligent in not importing directly from ‘@ionic/angular’.