mjs module resolution for React Native/Metro is broken
See original GitHub issueerror While trying to resolve module `use-context-selector` from file
`/Users/groza/Work/welearn/welearn-app/src/components/UI/video-player/VideoPlayerController.tsx`, the package `/Users/groza/Work/welearn/welearn-app/node_modules/use-context-selector/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/groza/Work/welearn/welearn-app/node_modules/use-context-selector/dist/index.native.modern.js`. Indeed, none of these files exist:
* /Users/groza/Work/welearn/welearn-app/node_modules/use-context-selector/dist/index.native.modern.js(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.mjs|.native.mjs|.mjs)
* /Users/groza/Work/welearn/welearn-app/node_modules/use-context-selector/dist/index.native.modern.js/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.mjs|.native.mjs|.mjs).
my metro.config.js (i’ve already added mjs here):
const defaultSourceExts = require('metro-config/src/defaults/defaults').sourceExts;
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
resolver: {
sourceExts: process.env.RN_SRC_EXT
? [...process.env.RN_SRC_EXT.split(',').concat(defaultSourceExts), 'mjs']
: [...defaultSourceExts, 'mjs'],
},
};
manually changing
"react-native": "./dist/index.native.modern.js",
to
"react-native": "./dist/index.native.modern.mjs",
or
"react-native": "./dist/index.native.modern",
allows the build to go through
same thing for manually renaming index.native.modern.mjs to index.native.modern.js
RN version 0.68.0
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Add .cjs and .mjs files support · Issue #535 · facebook/metro
Error: While trying to resolve module `lib` from file `project/index.js`, the package `project/node_modules/lib/package.json` was ...
Read more >Metro Bundler fails while trying to resolve module `immer ...
mjs file but no H:\my_project\app\node_modules\immer\dist\immer.esm.mjs\ folder with an index file in it. So I tried to manually remove ...
Read more >Module Resolution | Metro - Meta Open Source
Module resolution is the process of translating module names to module paths at build time. For example, if your project contains the code:...
Read more >Plug'n'Play | Yarn - Package Manager
An overview of Plug'n'Play, a powerful and innovative installation strategy for Node.
Read more >What does it take to support Node.js ESM? – The Guild
js , set "type": "module" , and the CommonJS version of your modules with the .cjs extension. Clearly using the .mjs extension is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://www.npmjs.com/package/use-context-selector/v/1.4.1
@sf185127 Thanks for confirming!