react-native-mmkv icon indicating copy to clipboard operation
react-native-mmkv copied to clipboard

Issue with [email protected] on [email protected] with New Architecture

Open chandani-c-simform opened this issue 11 months ago • 13 comments

I’m facing an issue with react-native-mmkv (v3.2.0) on a project using:

React Native: 0.76.5 New Architecture: Enabled react-native-web: 0.19.12 react-native-mmkv: 3.2.0

The library works as expected on native platforms (Android/iOS), but running the app on the web results in the following errors:

ERROR in ./node_modules/react-native-mmkv/lib/module/index.js 3:0-23 Module not found: Error: Can't resolve './MMKV' in '/Users/example/node_modules/react-native-mmkv/lib/module' Did you mean 'MMKV.js'? BREAKING CHANGE: The request './MMKV' failed to resolve only because it was resolved as fully specified (probably because the origin is strict EcmaScript Module, e.g., a module with JavaScript mimetype, a '.mjs' file, or a '.js' file where the package.json contains '"type": "module"'). The extension in the request is mandatory for it to be fully specified. Add the extension to the request.

ERROR in ./node_modules/react-native-mmkv/lib/module/index.js 4:0-24 Module not found: Error: Can't resolve './hooks' in '/Users/example/node_modules/react-native-mmkv/lib/module' Did you mean 'hooks.js'? BREAKING CHANGE: The request './hooks' failed to resolve only because it was resolved as fully specified (probably because the origin is strict EcmaScript Module, e.g., a module with JavaScript mimetype, a '.mjs' file, or a '.js' file where the package.json contains '"type": "module"'). The extension in the request is mandatory for it to be fully specified. Add the extension to the request.

ERROR in ./node_modules/react-native-mmkv/lib/module/index.js 5:0-31 Module not found: Error: Can't resolve './Types' in '/Users/example/node_modules/react-native-mmkv/lib/module' Did you mean 'Types.js'? BREAKING CHANGE: The request './Types' failed to resolve only because it was resolved as fully specified (probably because the origin is strict EcmaScript Module, e.g., a module with JavaScript mimetype, a '.mjs' file, or a '.js' file where the package.json contains '"type": "module"'). The extension in the request is mandatory for it to be fully specified. Add the extension to the request.

chandani-c-simform avatar Jan 20 '25 07:01 chandani-c-simform

Guten Tag, Hans here! 🍻 Thank you for providing zese details about your issue with react-native-mmkv on react-native-web. It seems like you're facing module resolution errors due to missing file extensions in your imports.

To resolve ze errors, try changing your import statements in index.js to include ze file extensions, for example:

import './MMKV.js';
import './hooks.js';
import './Types.js';

Let me know if zis helps, or if you still encounter any issues. If you find zis library helpful, consider supporting ze project by becoming a sponsor!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

maintenance-hans[bot] avatar Jan 20 '25 07:01 maintenance-hans[bot]

@mrousavy @amutsch Could you please help me with the same?

chandani-c-simform avatar Jan 20 '25 07:01 chandani-c-simform

(NOBRIDGE) ERROR Error: Failed to create a new MMKV instance: The native MMKV Module could not be found.

  • Make sure react-native-mmkv is correctly autolinked (run npx react-native config to verify)
  • Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the react-native-mmkv specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md
  • Make sure you are using react-native 0.74.0 or higher, because react-native-mmkv is a C++ TurboModule.
  • Make sure you rebuilt the app.
  • Make sure gradle is synced. [Component Stack]

Does anyone have any fix for this?

mohit0129 avatar Feb 02 '25 08:02 mohit0129

@chandani-c-simform resolved here #792

enavermate avatar Feb 05 '25 15:02 enavermate

@enavermate The solution mentioned by you applies to Expo CLI, However I'm facing an issue with React Native CLI.

chandani-c-simform avatar Feb 06 '25 11:02 chandani-c-simform

What are you using to bundle your web, I am using this in my web project without RN-Web so I am assuming the addition of RN web is irrelevant, it is likely an issue in the config of the bundler and how it is accessing files

amutsch avatar Feb 06 '25 12:02 amutsch

here is my extension resolution order on my web project config.resolve.extensions = ['.web.ts', '.ts', '.web.tsx', '.tsx', '.mjs', '.web.js', '.js', '.web.jsx', '.jsx']

amutsch avatar Feb 06 '25 12:02 amutsch

@amutsch It seems slight misunderstanding in this, we are having react native cli project and to add support of web within it we will have to go with react-native-web. It is not reactJS project. For this we will have to go through related webpack config only. However I have tried with solution you have provided, but it doesn't make any difference. May be you can even try it out by adding rn-web in your existing react native project, you might be able to reproduce the issue.

chandani-c-simform avatar Feb 06 '25 13:02 chandani-c-simform

I had RN-web based project at one point, I ripped it out as I didn't want it but I share significant code. I made the changes that allow react-native-mmkv to work in web without RN-web so I have run 3.2 with and without RN-web in my project. The problem would be in typescript configuration and webpack configuration. based on the stack trace you are reaching into ESM module code from something that wants commonjs

amutsch avatar Feb 06 '25 13:02 amutsch

(NOBRIDGE) ERROR Error: Failed to create a new MMKV instance: The native MMKV Module could not be found.

  • Make sure react-native-mmkv is correctly autolinked (run npx react-native config to verify)
  • Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the react-native-mmkv specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md
  • Make sure you are using react-native 0.74.0 or higher, because react-native-mmkv is a C++ TurboModule.
  • Make sure you rebuilt the app.
  • Make sure gradle is synced. [Component Stack]

Does anyone have any fix for this?

I am alsos facing same issue.

hmnz-tushar avatar Apr 19 '25 10:04 hmnz-tushar

me too

theocerutti avatar May 04 '25 16:05 theocerutti

(NOBRIDGE) ERROR Error: Failed to create a new MMKV instance: The native MMKV Module could not be found.

  • Make sure react-native-mmkv is correctly autolinked (run npx react-native config to verify)
  • Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the react-native-mmkv specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md
  • Make sure you are using react-native 0.74.0 or higher, because react-native-mmkv is a C++ TurboModule.
  • Make sure you rebuilt the app.
  • Make sure gradle is synced. [Component Stack]

Does anyone have any fix for this?

I am alsos facing same issue.

Do you have new architecture enabled, required for react-native-mmkv 3.x

amutsch avatar May 05 '25 11:05 amutsch

I ran into the same issue while using react-native-mmkv with Webpack (React Native Web setup), and resolved it by updating the Webpack config to allow non-fully-specified imports for .js and .mjs files.

✅ Setup:

  • react-native: 0.78.2
  • react-native-web: 0.20.0
  • react-native-mmkv: 3.2.0

Adding the following rule to webpack.config.js at fixed it:

module: {
      rules: [
        // other rules
        {
          test: /\.m?js$/,
          resolve: {
            fullySpecified: false
          }
        }
      ]
    }

💡 This tells Webpack not to require full file extensions for .js/.mjs imports (which Metro bundler doesn't enforce), allowing modules like ./createMMKV or ./MMKV to resolve correctly without appending .js.

No negative impact was observed in the rest of the project, and this is a common compatibility workaround for mixed ESM/CommonJS packages in React Native Web environments.

Hope this helps others facing similar issues!

dhruv-h-simform avatar Jun 02 '25 11:06 dhruv-h-simform

Hey - I don't think anything in MMKV changed, so I'm closing this issue. If you find a fix, PRs are welcome.

mrousavy avatar Aug 20 '25 14:08 mrousavy

Hey all, I am also running into this issue but @dhruv-h-simform's suggestion worked! However, I am now running into the issue described here.

My setup is

react-native: 0.76.9 react-native-web: 0.21.1 react-native-mmkv: 3.0.2

Any help would be greatly appreciated

jlee30-dev avatar Sep 10 '25 20:09 jlee30-dev