Issue resolving dependency to `use-force-update` in react-native/expo project
See original GitHub issueHey Charles,
I am running into an issue with an Expo/React-Native project resolving the reactn
dependency to use-force-update
.
I get the following errors (picture, and then error text…)
iOS Bundling failed 1265ms
While trying to resolve module `use-force-update` from file `/Users/m4ttheweric/Documents/GitHub/mbmd-expo/node_modules/reactn/build/use-dispatch.js`, the package `/Users/m4ttheweric/Documents/GitHub/mbmd-expo/node_modules/use-force-update/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/m4ttheweric/Documents/GitHub/mbmd-expo/node_modules/use-force-update/dist/cjs/index.cjs`. Indeed, none of these files exist:
* /Users/m4ttheweric/Documents/GitHub/mbmd-expo/node_modules/use-force-update/dist/cjs/index.cjs(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
* /Users/m4ttheweric/Documents/GitHub/mbmd-expo/node_modules/use-force-update/dist/cjs/index.cjs/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
I was able to resolve it by making a small change to the package.json
to use-force-update
within the node_modules
dir.
Before:
{
"main": "./dist/cjs/index.cjs"
}
After:
{
"main": "./dist/esm/index.js"
}
Any ideas on why this is occurring? I’m not familiar with the cjs/esm setup you’re using, so I don’t want to comment as to whether my solution is “good”.
Thanks!
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
No results found
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 Free
Top 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
This looks like an issue with “MetroJS bundler” not supporting
.cjs
extensions natively.https://stackoverflow.com/questions/60124435/however-this-package-itself-specifies-a-main-module-field-that-could-not-be-r
Looks like you need to edit your existing
metro.config.js
file (or make one if it does not already exist), then addcjs
to theresolver.sourceExts
array.Let me know if the above StackOverflow solutions don’t unblock you. I can see what else I can do, but I am ultimately relunctant to change the file extension of the bundled CommonJS file, because the different file extension is a requirement for newer versions of Node to distinguish CommonJS from ESM files in the same package.
Hi Charles,
Thanks for the library, could you release an update to reactn that has the fixed use-force-update dependency ? We use reactn in a LOT of projects…
Thanks,
Théo