Rename files to `cjs.js` for compatibility with React Native
See original GitHub issueImporting @solana/web3.js in React Native throws the following error.
error: Error: While trying to resolve module `superstruct` from file `/Users/sluscher/mobile-wallet-adapter/js/node_modules/@solana/web3.js/lib/index.browser.cjs.js`, the package `/Users/sluscher/mobile-wallet-adapter/js/node_modules/superstruct/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/sluscher/mobile-wallet-adapter/js/node_modules/superstruct/lib/index.cjs`. Indeed, none of these files exist:
* /Users/sluscher/mobile-wallet-adapter/js/node_modules/superstruct/lib/index.cjs(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
You can see that the React Native packager expects a .js
extension in addition to .cjs
If superstruct
could rename the CommonJS bundles from .cjs
to .cjs.js
that would make it Just Work™ for React Native folks!
More details on the problem here, if you’re interested: https://github.com/facebook/metro/issues/535
Issue Analytics
- State:
- Created a year ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Unable to Resolve Module in React Native App - Stack Overflow
I was using Intellij and created a js file, but it did not have the file extension. When I did a refractor rename...
Read more >react-native-rename - npm
Rename react -native app with just one command. Latest version: 3.0.2 ... Start using react-native-rename in your project by running `npm i react-native-rename`....
Read more >Migrating an NPM package to use ES Modules - Medium
In this article, I'm going to show you the steps needed to convert an NPM package from using CommonJS (CJS) modules, to the...
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
This setting controls whether .js files are interpreted as ES modules or ... To overlay the way TypeScript works in this system, .ts...
Read more >Node Modules at War: Why CommonJS and ES ... - Code Red
CJS is the default; you have to opt-in to ESM mode. You can opt-in to ESM mode by renaming your script from .js...
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
Hi @ianstormtaylor, we have run into the same issue and really expect a new release of superstruct to address this. Thanks heaps!
For sure. I would have done that in the moment, but I had too much mental stack to switch. If I get to it first, cool; if someone reading this wants to take a crack at it, cooler!