First, I had the error, "Unable to resolve module util
". So I ran npm install util
which solved the problem. Then I have the error, "Can't find variable: Buffer".
If I don't import Amplify, then No error occurs. It is a brand new project.
"dependencies": {
"aws-amplify": "^0.4.0",
"aws-amplify-react-native": "^0.2.11",
"react": "16.2.0",
"react-native": "0.52.0",
}
I tried "aws-amplify": and 0.1.0 and "aws-amplify-react-native": "^0.2.11",
here is my react-native info
:
Environment:
OS: macOS High Sierra 10.13.4
Node: 10.0.0
Yarn: 1.6.0
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.3 Build version 9E145
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.4
I have follow this solution > https://github.com/aws/aws-amplify/issues/140
but instead with :
"devDependencies": {
...,
"rn-nodeify": "github:tradle/rn-nodeify"
}
It is worked but dependencies became a mess and also some warnings are showing on debug:
Module RCTImageLoader requires main queue setup since it overrides
init
but doesn't implementrequiresMainQueueSetup
. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.
Module RNRandomBytes requires main queue setup since it overrides
constantsToExport
but doesn't implementrequiresMainQueueSetup
. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.
Once I connect it to AWS, got error: Unable to resolve module ‘stream’
Thanks in advance
I keep getting the same error.
Any help with this issue will be greatly appreciated.
@rhishikeshj you can do a npm i util buffer
then add this line in the lib/index.js
of the aws-amplify package:
global.Buffer = global.Buffer || require('buffer').Buffer
You will be able to at least launch your app for debugging untill this issue is resolved
@Quelu Thank you so much for the workaround ! Now atleast I can start my app's code to integrate Cognito 👍
I got same error...
My Project was created by using CRNA.
Package.json
"dependencies": {
"aws-amplify": "^0.4.0",
"aws-amplify-react-native": "^0.2.11",
"expo": "^27.0.1",
"react": "16.3.1",
"react-native": "~0.55.2",
"react-navigation": "^2.0.1"
}
react-native info
Environment:
OS: Windows 10
Node: 8.9.0
Yarn: 1.6.0
npm: 5.5.1
Watchman: Not Found
Xcode: N/A
Android Studio: Not Found
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: ~0.55.2 => 0.55.3
After I install util and buffer and add fix in lib/index.js of the aws-amplify package.
I get following error message when I try to sign in.
Can't find variable: crypto
- node_modules\crypto-browserify\rng.js:7:11 in exports
- node_modules\crypto-browserify\index.js:22:26 in randomBytes
- node_modules\amazon-cognito-identity-js\src\AuthenticationHelper.js:96:34 in generateRandomSmallA
- node_modules\amazon-cognito-identity-js\src\AuthenticationHelper.js:56:23 in AuthenticationHelper
- node_modules\amazon-cognito-identity-js\src\CognitoUser.js:225:6 in authenticateUserDefaultAuth
- node_modules\amazon-cognito-identity-js\src\CognitoUser.js:201:46 in authenticateUser
- node_modules\aws-amplify\lib\Auth\Auth.js:320:34 in <unknown>
- node_modules\promise\setimmediate\core.js:45:7 in tryCallTwo
- node_modules\promise\setimmediate\core.js:200:23 in doResolve
- node_modules\promise\setimmediate\core.js:66:12 in Promise
- node_modules\aws-amplify\lib\Auth\Auth.js:319:27 in signIn
@Quelu THANK YOU!
In case anyone is having that problem after upgrading to Angular 6 and using cognito, I've written a SO answer that might help: https://stackoverflow.com/a/50377270/2398593
@vincen7su I managed to work around the "Can't find variable: crypto" error by adding the following to the top of my App.js
. It's a bit of a hack though... looking forward to a proper fix!
global.crypto = require('crypto-browserify');
global.crypto.getRandomValues = (byteArray) => {
for (let i = 0; i < byteArray.length; i++) {
byteArray[i] = Math.floor(256 * Math.random());
}
};
I am also having issues with the CRNA and aws-amplify in a similar environment using expo. I ran the link commands but for some reason I still get an error where the util package is required in the sha.js package
The similar issue results in this error:
The package at ".<removed>\\node_modules\\sha.js\\sha1.js" attempted to import the Node standard library module "util". It failed because React Native does not include the Node standard library. Read more at https://docs.expo.io/versions/latest/introduction/faq.html#can-i-use-nodejs-packages-with-expo
Environment:
OS: Windows 10
Node: 8.11.1
Yarn: Not Found
npm: 6.0.1
Watchman: Not Found
Xcode: N/A
Android Studio: Version 3.0.0.0 AI-171.4443003
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: ~0.55.2 => 0.55.4
expo version 54.0.0
Finally Running: "npm ls sha.js"
[email protected] <removed>
`-- [email protected]
`-- [email protected]
`-- [email protected]
`-- [email protected]
@djungelorm Thank you! It works!
Are these workaround code are needed when building standalone app?
(I build app by using expo's service)
I solved this problem!
add package.json
"dependencies": {
"amazon-cognito-identity-js": "2.0.3",
...
}
Also having this issue with React Native. @Quelu suggestion actually did solve temporarily for me on React Native as well.
we have rolled/unpublished 2.0.5 due to the issues and are looking into migrating the crypto library to another option.
I'm getting this same error, any idea of a fix? It might be related to using aws-sdk with webpack, as described here: https://www.javascriptstuff.com/aws-sdk-with-webpack/, but their solutions aren't working for me
Hey @Victordmdb what version of Amplify & Amplify React Native are you running?
I tried with 1.0.1 and 1.0.3. Both with the same issue. It was always to do with the aws-sdk. I tried editing the aws-amplify package to modify the elements which where showing errors, but then I started getting an error with crypto. I assume it might have to do with my webpack setup, but I tried a bunch of different things and it didn't seem to have an effect.
I wasn't using native, only "aws-amplify" and "aws-amplify-react"
Most helpful comment
@rhishikeshj you can do a
npm i util buffer
then add this line in thelib/index.js
of the aws-amplify package:global.Buffer = global.Buffer || require('buffer').Buffer
You will be able to at least launch your app for debugging untill this issue is resolved