I am using the Angular 12.3 version and webpack:5. I installed the "authorizenet": "^1.0.8" version from npm: authorizenet.
I wrote a simple method in service to fetch customer profile called GetCustomerProfile. Initially, there were a lot of errors related to webpack when I imported authorize net library into the service.
Example:
import { APIContracts, APIControllers, Constants } from 'authorizenet/lib/authorizenet';
i.e.,"BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it."
I solved it by adding a webpack config in a project like this:
Now the problem is when I navigate to the component where this service is injected, the whole module fails to load with an error: Module xxx cannot be load before initialization.
When I comment above service method, the application starts working.
When I further look into the console in debugging, the error looks like this:
core.js:6479 ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'indexOf') TypeError: Cannot read properties of undefined (reading 'indexOf') at supports-colors.js:29:1 at 646 (supports-colors.js:61:2) at __webpack_require__ (bootstrap:19:1) at 75290 (colors.js:39:24) at __webpack_require__ (bootstrap:19:1) at 3385 (safe.js:8:14) at __webpack_require__ (bootstrap:19:1) at 55624 (config.js:9:14) at __webpack_require__ (bootstrap:19:1) at 13063 (common.js:15:14) at resolvePromise (zone.js:1213:1) at resolvePromise (zone.js:1167:1) at zone.js:1279:1 at ZoneDelegate.invokeTask (zone.js:406:1) at Object.onInvokeTask (core.js:28659:1) at ZoneDelegate.invokeTask (zone.js:405:1) at Zone.runTask (zone.js:178:1) at drainMicroTaskQueue (zone.js:582:1)
I applied many solutions from google, but nothing is working out.
The angular build is successful, All other modules work fine. Only a particular module throws an error at runtime. This only happened when I enabled the service method.
I am looking for assistance from the community on what the issue can be and how to move forward with that.