Skip to content

bug: Directory import is not supported resolving ES modules #30730

Closed

Description

@rthouvenin

Prerequisites

Ionic Framework Version

v8.x

Current Behavior

When I run unit tests in a component library that I am building, I face the following error:

Error: Directory import '[domain-lib-repo]/node_modules/@ionic/core/components' is not supported resolving ES modules imported from '[domain-lib-repo]/node_modules/@ionic/vue/dist/index.js
Did you mean to import "@ionic/core/components/index.js"?

Expected Behavior

Ability to run unit tests with vitest without a build error.

Steps to Reproduce

In the project I am working on, I am producing a "generic" components library, use by a "domain-specific" components library, and both are used in the final app.
Both libs are build with Vite in lib mode with rollup, with vue and @ionic/vue declared as dev and peer dependencies, and rollup configured to treat these packages as external. Here is what the vite config looks like:

export default defineConfig({
  plugins: [vue(), dts({ insertTypesEntry: true })],
  build: {
    lib: {
      entry: "src/index.ts",
      name: "MyLib",
      fileName: "my-lib",
    },
    rollupOptions: {
      external: ["vue", "vue-i18n", "vue-router", "@ionic/vue"],
      output: {
        globals: {
          vue: "Vue",
          "vue-i18n": "VueI18n",
          "vue-router": "VueRouter",
          "@ionic/vue": "IonicVue",
        },
      },
    },
  },
});

When I run unit tests in the domain-specific library, I face the following error:

Error: Directory import '[domain-lib-repo]/node_modules/@ionic/core/components' is not supported resolving ES modules imported from '[domain-lib-repo]/node_modules/@ionic/vue/dist/index.js
Did you mean to import "@ionic/core/components/index.js"?

Interestingly, out of the two components that I have started writing, the tests for one of them work fine, but not the other. The only relevant difference I can see is that the failing component makes use of a component from the "generic" library.

Unfortunately, I was not able to create a minimum reproducing scenario so far. But I notice that in @ionic/vue/dist/index.js, there is an import line 80 (for version 8.7.7) to @ionic/core/components:

import { LIFECYCLE_WILL_ENTER, LIFECYCLE_DID_ENTER, LIFECYCLE_WILL_LEAVE, LIFECYCLE_DID_LEAVE, initialize, modalController as modalController$1, popoverController as popoverController$1, alertController as alertController$1, actionSheetController as actionSheetController$1, loadingController as loadingController$1, pickerController as pickerController$1, toastController as toastController$1 } from '@ionic/core/components';

Since the package now exports only an ES module, isn't that an incorrect statement in the build output of @ionic/vue? Shouldn't it be @ionic/core/components/index.js like the error mentions?

Code Reproduction URL

Ionic Info

Ionic:

Ionic CLI : 7.2.1 (/home/romain/.nvm/versions/node/v20.19.5/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/vue 8.4.2

Capacitor:

Capacitor CLI : 6.2.1
@capacitor/android : 6.2.0
@capacitor/core : 6.2.1
@capacitor/ios : not installed

Utility:

cordova-res : not installed globally
native-run : 2.0.1

System:

NodeJS : v20.19.5 (/home/romain/.nvm/versions/node/v20.19.5/bin/node)
npm : 10.8.2
OS : Linux 6.8

Additional Information

No response

Activity

  1. added
    ionitron: needs reproduction
    on Oct 17, 2025
  2. ionitron-bot commented on Oct 17, 2025

    @ionitron-bot

    Thanks for the issue! This issue has been labeled as needs reproduction. This label is added to issues that need a code reproduction.

    Please reproduce this issue in an Ionic starter application and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed.

    If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue.

    For a guide on how to create a good reproduction, see our Contributing Guide.

  3. rthouvenin commented on Oct 21, 2025

    @rthouvenin
    Author

    I'll continue to try creating a minimum reproducing set-up, but don't you agree that regardless of how I use Ionic, the built package contains a JS statement that is invalid for a ES module?

  4. rthouvenin commented on Oct 21, 2025

    @rthouvenin
    Author

    I finally managed to pin down a fairly minimal scenario:

    git clone https://gitlab.com/rthouvenin/ionic-repro.git
    cd ionic-repro/group-ui
    npm i
    npm run build # Not necessary, but notice that the build works fine
    npm run test # => Error

    The group-ui folder contains the code for a minimal component library. It depends on another components library @rthouvenin/ionic-repro-base-lib, built similarly with the code in the my-lib folder and published on npmjs registry.

    Some clues that may help explain the problem or why it does not occur more often:

    • npm run test -- tests/components/IndieTile.spec.ts runs without error. IndieTile and its test don't make use of @rthouvenin/ionic-repro-base-lib
    • If you npm install ../my-lib to get the package locally instead of from the registry, npm run test works without error
  5. ShaneK commented on May 29, 2026

    @ShaneK
    Member

    Hey! I have a PR built off of major-9.0 that will address this issue. There's a dev build here if you would like to verify for yourself:

    8.8.9-dev.11780086312.13aac420
    

    However, it is based off of major-9.0 because it is technically a breaking change in that it limits the imports that can be used to officially documented imports. I considered this breaking behavior because we don't know who is importing what and how.

    There's also other big changes in major-9.0 already that may cause this dev build to have issues with a bigger project, but it did pass against your reproduction repo.

  6. added a commit that references this issue on Jun 1, 2026
    312a3a7
  7. reopened this on Jun 1, 2026
  8. ionitron-bot commented on Sep 18, 2026

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  9. locked and limited conversation to collaborators on Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ionitron: needs reproduction

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions