问题描述
我使用cli创建了一个Angular应用。
创建了组件等。一切正常。
然后在我的服务中,我导入了软件包pm2
和dayjs
。已安装npm i pm2 --save
并编写了以下代码:
import * as Pm2 from 'pm2';
import * as DayJs from 'dayjs';
services = [];
readPm2(): void {
Pm2.connect((err) => {
if (err) {
throw (err);
} else {
Pm2.list((err,data) => {
if (err) {
throw (err);
} else {
data.forEach(service => {
this.services.push({
name: service.name,status: status[service.pm2_env.status] || 'unkNown',cpu: `${service.monit.cpu}%`,mem: `${this.round(service.monit.memory / 1024 / 1024,2).toFixed(2)}mb`,started: DayJs(service.pm2_env.pm_uptime).format('HH:mm:ss')
});
});
}
Pm2.disconnect();
});
}
});
}
我之前在干净的NodeJs应用中尝试过此功能,并且一切正常。
当我现在尝试运行ng serve
时,我收到大量错误的抱怨,因为它找不到几个模块,这些模块我自己都不在哪里导入。它们必须是pm2
或dayjs
的依赖项。
以下是一些错误:
ERROR in ./node_modules/amp/lib/stream.js
Module not found: Error: Can't resolve 'stream' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/amp/lib'
ERROR in ./node_modules/charm/index.js
Module not found: Error: Can't resolve 'stream' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/charm'
ERROR in ./node_modules/mute-stream/mute.js
Module not found: Error: Can't resolve 'stream' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/mute-stream'
ERROR in ./node_modules/needle/lib/needle.js
Module not found: Error: Can't resolve 'stream' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/needle/lib'
ERROR in ./node_modules/needle/lib/parsers.js
Module not found: Error: Can't resolve 'stream' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/needle/lib'
ERROR in ./node_modules/needle/lib/decoder.js
Module not found: Error: Can't resolve 'stream' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/needle/lib'
ERROR in ./node_modules/readdirp/index.js
Module not found: Error: Can't resolve 'stream' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/readdirp'
ERROR in ./node_modules/blessed/lib/widgets/terminal.js
Module not found: Error: Can't resolve 'term.js' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/blessed/lib/widgets'
ERROR in ./node_modules/charm/index.js
Module not found: Error: Can't resolve 'tty' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/charm'
ERROR in ./node_modules/pm2/lib/Common.js
Module not found: Error: Can't resolve 'vm' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/pm2/lib'
ERROR in ./node_modules/blessed/vendor/tng.js
Module not found: Error: Can't resolve 'zlib' in '/Users/hot/Documents/Dev/HOT_SP/sptools/Watchguard/node_modules/blessed/vendor'
ERROR in ./node_modules/pm2-deploy/deploy 1:0
Module parse Failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type,currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> #!/usr/bin/env bash
|
| #
ERROR in ./node_modules/fsevents/fsevents.node 1:0
Module parse Failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type,currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
"browser": {
"stream": false,"os": false,"fs": false
}
这些模块的错误消息不再通过运行serve命令出现。但这是解决此问题的正确解决方案吗?我需要在此列表中添加20个软件包。
如果认为这可能是一个问题,因为这些缺少的依赖项在纯Js中,因此我尝试添加:
"allowJs": true
有人可以向我解释一下,并为此提供解决方案。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)