npm install redis
运行ng serve后报错
解决方法:
npm install net
npm install tls
之后再运行ng serve后没有报错,但是进入页面后又有问题:
process is not defined at Object../node_modules/redis-errors/index.js (index.js:3) at __webpack_require__
解决方法:
在polyfills.ts中加入以下代码:
(window as any).global = window;
//global.Buffer = global.Buffer || require('buffer').Buffer;
global.process = require('process');
在运行ng serve后又报错:
ERROR in polyfills.ts:85:1 - error TS2304: Cannot find name 'global'.
polyfills.ts:86:18 - error TS2591: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types
field in your tsconfig.
86 global.process = require('process');
~~~~~~~
解决方法:
在tsconfig.app.json 中加入
"types": [
"node"
]
再运行之后就没有报错了。