Get error Uncaught ReferenceError: global is not defined
brianreinhold opened this issue · 1 comments
Describe the Bug
- When Visual studio starts up I get the error:
- [2023-11-14 00:00:28.538] [ERROR] [KarmaTestExplorer]: Failed to load tests - Test discovery failed: Browser Error - An error was thrown in afterAll Uncaught ReferenceError: global is not defined
ReferenceError: global is not defined
Steps to Reproduce the Behavior
I may have to give you my project. It does use AWS Cognito for login the the Auth Amplify library
Describe the Expected Behavior
Tests should be discovered (all the tests are defaults as generated by angular/CLI
Provide Debug Logs
[2023-11-13 23:59:58.276] [INFO] [MainFactory]: Using test framework: jasmine (auto-detected)
[2023-11-13 23:59:58.277] [INFO] [AngularFactory]: Using Angular project 'HubView' at root path 'E:/projects/Angular/HubViewX' and karma config file ''
[2023-11-13 23:59:58.371] [INFO] [DefaultTestManager]: Using requested --> available karma port: 9976 --> 9976
[2023-11-13 23:59:58.387] [INFO] [DefaultTestManager]: Using requested --> available karma listener socket port: 9999 --> 9999
[2023-11-13 23:59:58.415] [INFO] [DefaultTestManager]: Using requested --> available debug port: 9222 --> 9222
[2023-11-13 23:59:58.417] [INFO] [KarmaTestServer]: Starting karma server
[2023-11-13 23:59:58.706] [INFO] [KarmaTestListener]: Waiting for Karma to connect on port 9999
[2023-11-14 00:00:25.393] [INFO] [KarmaTestListener]: Established new connection with Karma on port 9999
[2023-11-14 00:00:26.440] [INFO] [DefaultTestManager]: Discovering tests
[2023-11-14 00:00:28.537] [ERROR] [KarmaTestRunProcessor]: Browser error while listening for test events: Browser Error - An error was thrown in afterAll
Uncaught ReferenceError: global is not defined
ReferenceError: global is not defined
at Object.7836 (http://localhost:9976/_karma_webpack_/webpack:/node_modules/buffer/index.js:43:30)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.1021 (http://localhost:9976/_karma_webpack_/vendor.js:9566:64)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.6938 (http://localhost:9976/_karma_webpack_/vendor.js:13832:79)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.1529 (http://localhost:9976/_karma_webpack_/vendor.js:27:84)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.9694 (http://localhost:9976/_karma_webpack_/main.js:9969:69)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
[2023-11-14 00:00:28.537] [ERROR] [KarmaTestRunProcessor]: Could not capture Karma events - Test execution failed: Browser Error - An error was thrown in afterAll
Uncaught ReferenceError: global is not defined
ReferenceError: global is not defined
at Object.7836 (http://localhost:9976/_karma_webpack_/webpack:/node_modules/buffer/index.js:43:30)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.1021 (http://localhost:9976/_karma_webpack_/vendor.js:9566:64)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.6938 (http://localhost:9976/_karma_webpack_/vendor.js:13832:79)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.1529 (http://localhost:9976/_karma_webpack_/vendor.js:27:84)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.9694 (http://localhost:9976/_karma_webpack_/main.js:9969:69)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
[2023-11-14 00:00:28.538] [ERROR] [DefaultTestManager]: Test discovery failed: Browser Error - An error was thrown in afterAll
Uncaught ReferenceError: global is not defined
ReferenceError: global is not defined
at Object.7836 (http://localhost:9976/_karma_webpack_/webpack:/node_modules/buffer/index.js:43:30)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.1021 (http://localhost:9976/_karma_webpack_/vendor.js:9566:64)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.6938 (http://localhost:9976/_karma_webpack_/vendor.js:13832:79)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.1529 (http://localhost:9976/_karma_webpack_/vendor.js:27:84)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.9694 (http://localhost:9976/_karma_webpack_/main.js:9969:69)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
[2023-11-14 00:00:28.538] [ERROR] [KarmaTestExplorer]: Failed to load tests - Test discovery failed: Browser Error - An error was thrown in afterAll
Uncaught ReferenceError: global is not defined
ReferenceError: global is not defined
at Object.7836 (http://localhost:9976/_karma_webpack_/webpack:/node_modules/buffer/index.js:43:30)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.1021 (http://localhost:9976/_karma_webpack_/vendor.js:9566:64)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.6938 (http://localhost:9976/_karma_webpack_/vendor.js:13832:79)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.1529 (http://localhost:9976/_karma_webpack_/vendor.js:27:84)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at Module.9694 (http://localhost:9976/_karma_webpack_/main.js:9969:69)
at webpack_require (http://localhost:9976/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
[2023-11-14 00:00:28.540] [INFO] [KarmaTestExplorer]: Finished loading tests in 30.26 secs (Failed)
[2023-11-14 00:00:28.547] [WARN] [KarmaTestRunProcessor]: Test run encountered an error (Exit code: 1) -
The global variable is defined in the polyfills.ts file:
(window as any).global = window;
(window as any).process = {
env: { DEBUG: undefined },
};
I have tried placing it in other files changing the angular and typescript config files accordingly. The result is always as above.
@brianreinhold Note that with the deprecation of Karma runner, this extension is also now deprecated. While you continue to use Karma and this extension, I encourage you to post any new issues in the Discussions area to possibly get help from other users.
Having said that, this issue seems like an error in the Karma setup rather than the extension. Try checking if you're able to run the tests directly from the command line without the extension, or if you also run into this error in that scenario. Hope that helps. If not, post in the Discussions area in case other users are able to help.