superstruct
superstruct copied to clipboard
Rename files to `cjs.js` for compatibility with React Native
Importing @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
@steveluscher interesting, I'd be down for a PR if you want to make this change!
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!
PR'd.
Hi everyone, thanks very much for addressing this! I was having this issue using solana/web3.js and stumbled upon this. I downloaded @steveluscher's branch and tested it out locally and it was able to build.
Awesome! Let's shipit!
Hi @steveluscher
I'm experiencing the exact same problem:
iOS Bundling failed 409ms While trying to resolve module superstruct from file...
I have installed your branch yarn add git+https://github.com/steveluscher/superstruct.git#react-native-compatibility
but still get the same error.
Do you by any chance know if there's some additional configuration to do/link me to your "Getting Started" README ?
Thanks a lot in advance!
@valentinmadrid the package needs to be built, it can't be cloned directly from git. not sure if this is the right way, but i used the same yarn add ...
as you, but then also cloned steve's branch to a separate location. in that directory, i ran yarn install && yarn build
. this produced a directory named lib
. i copied that lib
directory to my project's node_modules/superstruct/
directory.
this seems to have worked but i immediately ran into other issues. i don't think they're related though.
We'll just have to be patient! Once @ianstormtaylor mashes the merge button on #1086 and does a release, we should all be able to update to that new release from npm.
Hi @ianstormtaylor, we have run into the same issue and really expect a new release of superstruct to address this. Thanks heaps!
Guys any resolution, i'm facing exactly same error:
"react-native": "0.69.6",
"@solana/web3.js": "1.66.1"
@AndonMitev: https://twitter.com/steveluscher/status/1565232097044099073
Thanks for this but i'm on "@solana/web3.js": "1.66.1"
with react-native: "0.69.6"
I know! You’ll have to upgrade to 0.70+ for support going forward. We’ve abandoned the 0.69- line.