微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular App:找不到已安装的JS软件包的依赖项

如何解决Angular App:找不到已安装的JS软件包的依赖项

我使用cli创建了一个Angular应用。

创建了组件等。一切正常。 然后在我的服务中,我导入了软件包pm2dayjs。已安装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时,我收到大量错误的抱怨,因为它找不到几个模块,这些模块我自己都不在哪里导入。它们必须是pm2dayjs的依赖项。

以下是一些错误

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)

如果我在package.json添加以下内容

"browser": {
    "stream": false,"os": false,"fs": false
}

这些模块的错误消息不再通过运行serve命令出现。但这是解决此问题的正确解决方案吗?我需要在此列表中添加20个软件包。

如果认为这可能是一个问题,因为这些缺少的依赖项在纯Js中,因此我尝试添加

"allowJs": true

致我的tsconfig.json无法解决此问题。

有人可以向我解释一下,并为此提供解决方案。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。