I am working on making an Angular app (Angular 9) as a side project. However, this one issue keeps persisting. Every time I try to run ng serve
, I'm prompted with a ton of these errors:
Module not found: Error: Can't resolve 'crypto' in 'node_modules/request/lib'
There are dozens of these same kinds of errors for crypto
, fs
, http
, https
, stream
, tls
, and zlib
as well. I have ran npm install ...
for all of these dependencies and they are in my node_modules folder. I've tried following some of the suggestions posted here (https://github.com/iden3/snarkjs/issues/17) and following this thread (Module not found: Error: Can't resolve 'crypto') such as updating my package.json to include after my devDependencies:
"browser": {
"crypto": false,
"stream": false,
"fs": false,
"http": false,
"https": false,
"tls": false,
"zlib": false
},
I also have in my tsconfig.json:
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"es2018",
"dom"
],
"types": ["node"],...
I get no compiler errors, but the console in the browser screams:
Uncaught ReferenceError: process is not defined
at Object../node_modules/request/lib/helpers.js (:4200/vendor.js:114108)
at __webpack_require__ (:4200/runtime.js:80)
at Object../node_modules/request/index.js (:4200/vendor.js:113314)
at __webpack_require__ (:4200/runtime.js:80)
When I take a peek into the readme in the crypto folder in my node modules, it said that is has been deprecated and that I should switch to the built-in Node module. I can't seem to find anything that explains how to tell Node to use its built-in crypto. Am I missing something here?
There seems to also be more discussion about this issue (https://github.com/angular/angular-cli/issues/1548) but I'm unaware of anything getting resolved? Does anyone have any workarounds? If the issue is with Node, how can I tell it to use the built-in crypto dependency?
Thanks!
Update:
From angular.json:
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "myproject:build"
},
"configurations": {
"production": {
"browserTarget": "myproject:build:production"
}
}
},