Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

> 3 | import __node_cjsModule from 'node:module'; #112

Closed
hanwenbo opened this issue Oct 12, 2024 · 3 comments · Fixed by #113
Closed

> 3 | import __node_cjsModule from 'node:module'; #112

hanwenbo opened this issue Oct 12, 2024 · 3 comments · Fixed by #113

Comments

@hanwenbo
Copy link

error: Error: Unable to resolve module node:module from /Users/xxx/node_modules/react-native-magic-modal/dist/index.js: node:module could not be found within the project or in these directories:
node_modules/react-native-magic-modal/node_modules
node_modules
../../node_modules
1 | import React, { Fragment, useMemo, memo, useCallback, useEffect, useImperativeHandle } from 'react';
2 | import { Platform, StyleSheet, Pressable, useWindowDimensions, View, BackHandler } from 'react-native';

3 | import __node_cjsModule from 'node:module';

@jvliwanag
Copy link

This issue appears when using the esm build of react-native-magic-modal which is picked up on expo projects when turning on unstable_enablePackageExports.

The esm build itself seems faulty such that it ends up using the require from node.

There's only one line of require here.

Since react-native-screens will always be there anyway for all platforms, I wonder if just using a traditional import will be a simpler fix.

A workaround for expo users now while leaving unstable_enablePackageExports on is patching this package inverting this package's package.json:

"exports": {
    "./package.json": "./package.json",
    ".": {
      "require": {
        "types": "./dist/index.d.cts",
        "default": "./dist/index.cjs"
      },
      "import": {
        "types": "./dist/index.d.ts",
        "default": "./dist/index.js"
      }
    }
  },

This makes expo pick-up the commonjs version first.

@GSTJ
Copy link
Owner

GSTJ commented Oct 15, 2024

Thanks for pinpointing! I agree with the solution. Will spin up a quick PR.

@GSTJ
Copy link
Owner

GSTJ commented Oct 16, 2024

Fixed, let me know if it solves this for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants