question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rename files to `cjs.js` for compatibility with React Native

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
charIeszhaocommented, Aug 30, 2022

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

1reaction
steveluschercommented, Jul 8, 2022

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found