Skip to content

Incorrect module imported when optional dependencies are used #1516

Description

@miquelbeltran

I am not 100% sure if this question belongs here or the RN repo, I apologize beforehand as well if questions are not allowed.

After updating to RN 0.79.3 (includes Metro 0.82.4), I started to experiment runtime errors with named imports/exports within our custom package.

For example, getting:

_$$_REQUIRE(_dependencyMap[8], "./Utils").getRandomGUID is not a function (is undefined).

getRandomGUID is part of the Utils.ts and is defined as follows:

export const getRandomGUID = (length: number): string => {
// etc.

And it is imported like this:

import { getRandomGUID } from './Utils';

To make it work, I had to switch to using a default export, instead of named exports:

In my Utils.ts:

export default {
  getRandomGUID,
  //etc
}

And change the way I import them:

import Utils from './Utils';
const { getRandomGUID } = Utils;

Any ideas of what might have changed here? Honestly, looking at the changelogs from RN and Metro, I cannot figure it out.

I have also disabled https://metrobundler.dev/docs/configuration/#unstable_enablepackageexports-experimental in our metro config from the demo app I use for testing, but it doesn't seem to affect it. We don't use that feature in our package and as I understand from https://metrobundler.dev/docs/package-exports/#migration-guide-for-package-maintainers it is entirely optional.

Any ideas would be appreciated, and I can provide more information if required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions