Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename files to cjs.js for compatibility with React Native #1085

Closed
steveluscher opened this issue Jul 7, 2022 · 13 comments · Fixed by #1086
Closed

Rename files to cjs.js for compatibility with React Native #1085

steveluscher opened this issue Jul 7, 2022 · 13 comments · Fixed by #1086
Labels

Comments

@steveluscher
Copy link
Contributor

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: facebook/metro#535

@steveluscher steveluscher changed the title Rename files to cjs.js for compatibility with React Native Rename files to cjs.js for compatibility with React Native Jul 7, 2022
@ianstormtaylor
Copy link
Owner

@steveluscher interesting, I'd be down for a PR if you want to make this change!

@steveluscher
Copy link
Contributor Author

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!

@steveluscher
Copy link
Contributor Author

PR'd.

@momolarson
Copy link

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.

@steveluscher
Copy link
Contributor Author

Awesome! Let's shipit!

@valentinmadrid
Copy link

valentinmadrid commented Aug 3, 2022

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!

@inhumantsar
Copy link

@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.

@steveluscher
Copy link
Contributor Author

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.

@charIeszhao
Copy link

Hi @ianstormtaylor, we have run into the same issue and really expect a new release of superstruct to address this. Thanks heaps!

@AndonMitev
Copy link

Guys any resolution, i'm facing exactly same error:

"react-native": "0.69.6",
"@solana/web3.js": "1.66.1"

@steveluscher
Copy link
Contributor Author

@AndonMitev
Copy link

Thanks for this but i'm on "@solana/web3.js": "1.66.1" with react-native: "0.69.6"

@steveluscher
Copy link
Contributor Author

I know! You’ll have to upgrade to 0.70+ for support going forward. We’ve abandoned the 0.69- line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants