amplify-js: Error "crypto could not be found within the project." on React Native
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React Native
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
# Put output below this line
Binaries:
Node: 14.16.1 - /usr/local/bin/node
npm: 6.14.12 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
npmPackages:
…
@react-native-async-storage/async-storage: ^1.15.4 => 1.15.4
@react-native-community/netinfo: ^6.0.0 => 6.0.0
amazon-cognito-identity-js: ^5.0.1 => 5.0.1 (5.0.0)
aws-amplify: ^4.0.2 => 4.0.2
…
npmGlobalPackages:
npm: 6.14.12
Describe the bug
Error “crypto could not be found within the project.” shows up when running React Native app with aws-amplify v4.0.2. aws-amplify v4.0.1 came with an upgrade of crypto-js from v3.3.0 to v4.0.0 (see changes) but it seems this version is not compatible with React Native (docs, issue).
Expected behavior
React Native app runs without any error.
Reproduction steps
- Install
aws-amplifyv4.0.2 in a React Native app along with its dependencies as per the docs (@react-native-async-storage/async-storage,@react-native-community/netinfo,amazon-cognito-identity-js) - Run the app in a debug environment
- See the error:
error: Error: Unable to resolve module `crypto` from `node_modules/@aws-amplify/auth/node_modules/crypto-js/core.js`: crypto could not be found within the project.
If you are sure the module exists, try these steps:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules: rm -rf node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
...
Code Snippet
// Put your code below this line.
Log output
// Put your logs below this line
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
Android, iOS
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 17 (4 by maintainers)
You shouldn’t need to manually install the previous version of CryptoJS. Please try performing a fresh re-install of your dependencies:
rm -rf node_modules package-lock.jsonnpm inpx pod-installOr using yarn:
rm -rf node_modules yarn.lockyarnnpx pod-installHave the same problem. For a quick workaround I installed the crypto-js version 3.3.0.
crypto-js version 3.3.0 seems to clear the issue for me as well