-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Uncaught ReferenceError: global is not defined (at node_modules/amazon-cognito-identity-js/node_modules/buffer/index.js (index.js:43:30)) #11175
Comments
Attaching the demo project, so you can just "yarn install" in it and will be able to see the error once you run the project. |
Hi @aoneahsan can you try out this solution I tried it on your sample project and the |
For future reference - depending on the project setup, the Vite / React plugin may also be required: import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
define: {
global: {},
},
server: {
port: 3000,
},
resolve: {
alias: {
'./runtimeConfig': './runtimeConfig.browser',
},
},
}); |
HI there @tannerabread sure let me try that (sorry for late reply) |
Any luck with that solution, @aoneahsan? |
i tried but i was not able to get it to work (and i did not understand what these local reference files were supposed to have in them (so yes if you can provide a demo project repo link will be helpfull or explain what I'm doing wrong (sorry for trouble))). |
Hi @david-mcafee |
Or a direct zip file here, whatever works for you. |
Hi @aoneahsan for your zipped project you posted earlier, to get it working what I did was change // vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
...(process.env.NODE_ENV === 'development'
? {
define: {
global: {},
},
}
: {}),
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/setupTests.ts',
}
}) |
@tannerabread |
@aoneahsan, can you see if updating the // vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import resolve from '@rollup/plugin-node-resolve';
// https://vitejs.dev/config/
export default defineConfig({
...(process.env.NODE_ENV === 'development'
? {
define: {
global: {},
},
}
: {}),
plugins: [
react(),
resolve()
],
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/setupTests.ts',
}
}) |
@cwomack |
@aoneahsan are you still getting the same build errors? If so, maybe this comment about including
Let me know if that doesn't work and what errors you're still seeing, please! |
Related to #9639 |
@aoneahsan - I have a sample Vite project that I use for testing against Amplify, could you compare your config / dependencies against what I have? Perhaps that may be the most straightforward way to see what your issue may be. Thanks!! |
I'm getting the same error with an Angular 15 project. The problem is that the buffer module, which is intended for use in the browser, refers to a |
Hey @Arlen22 , I use angular too. I don't know the rationale but you can try adding
Reference from this Uncaught ReferenceError: global is not defined |
Yeah, that's what I ended up doing. I also opened an issue on the buffer project, but since this is an older version with 13 million downloads, fixing this "bug" would be a breaking change, so I doubt it will happen there. |
@Arlen22 i'm also use angular 15, and what i done to avoid to touch the html was to expose a polyfills.ts file creating a file and refer to it from angular.json like "architect": {
"build": {
..
"options": {
...
"polyfills": [
"src/polyfills.ts"
],
... and add inside import 'zone.js';
(window as any).global = window; |
@Arlen22 @Naikno - I recently tested using Amplify with Angular following the Amplify "Getting Started" docs for Angular, and did not encounter any issues. Can you take a look at the guide and see if any of the guidance there resolves the issues you are seeing? Thanks! |
added define: {
global: {}
} worked for me |
thanks this is working.
inside define config |
really thanks man ...❤️ its working fine. |
I'm curious why this error only exists in Angular apps. I wrote an npm package and used the buffer package. It has no problem running in browser when testing, but after switching to Angular the problem appears. |
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
Describe the bug
index.js:43 Uncaught ReferenceError: global is not defined
at node_modules/amazon-cognito-identity-js/node_modules/buffer/index.js (index.js:43:30)
at __require2 (chunk-TFWDKVI3.js?v=4a4aa487:18:50)
at AuthenticationHelper.js:6:24
node_modules/amazon-cognito-identity-js/node_modules/buffer/index.js @ index.js:43
__require2 @ chunk-TFWDKVI3.js?v=4a4aa487:18
(anonymous) @ AuthenticationHelper.js:6
Expected behavior
I was working in ionic 6 + react project where it was using "react-scripts" to run the project, project was working fine, authentication was working as well.
because now we have ionic 7 so i upgraded my project, i created a new project and moved my code from old ionic 6 project to new ionic 7 project.
here now ionic have introduced "vite" in place of "react scripts" to run the project.
i have double checked that this error is with "Auth" module coming from "@aws-amplify/auth" by commenting "aws-amplify/auth" imports from project and project started working fine.
this line in "amazon-cognito-identity-js" package is giving this error, as you can see "global" constant is used here
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
i even tried resolving this error by adding
(window as any).global = window;
in my main.ts file but still getting this error.
Reproduction steps
Steps to reproduct the error (i have added a video link showing how i reproduced the error as well to help you through the process).
VIDEO LINK: https://www.awesomescreenshot.com/video/16170162?key=754ffb3f47ae3154f41b1df041c7511e
STEPS:
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: