为什么我的应用程序在运行时收到此错误,"ERROR in ./node_modules/@nestjs/common/cache/cache.providers.js"?



设置应用程序很容易。我刚刚用"ng new[应用程序名称]"创建了它。我添加了棱角分明的材料。我还通过ng-add@Nestjs/ng-universal添加了Nestjs的Angular universal服务器。我了解到我需要确保我没有使用Angular 10的CLI,所以我用Angular 9的CLI重新拨号,它一直在工作,直到我创建了Angular服务。在我创建了该服务,向该服务中添加了一个HttpClient,并在组件中使用了该服务之后,我开始出现导致应用程序崩溃的错误。

npm run dev:ssr
> fullstack-flip8@0.0.0 dev:ssr /Users/jeremy/MEGA/projects/FlipIt/fullstack-flip8
> ng run fullstack-flip8:serve-ssr
****************************************************************************************
This is a simple server for use in testing or debugging Angular applications locally.
It hasn't been reviewed for security issues.
DON'T USE IT FOR PRODUCTION!
****************************************************************************************
chunk {main} main.js, main.js.map (main) 323 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 141 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.css, styles.css.map (styles) 84.6 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 5.39 MB [initial] [rendered]
Date: 2020-07-20T17:37:04.757Z - Hash: 10e58d11f5f9b0ff406f - Time: 16897ms
WARNING in ./node_modules/@nestjs/common/utils/load-package.util.js 8:39-59
Critical dependency: the request of a dependency is an expression
ERROR in ./node_modules/@nestjs/common/cache/cache.providers.js
Module not found: Error: Can't resolve 'cache-manager' in '/Users/jeremy/MEGA/projects/FlipIt/fullstack-flip8/node_modules/@nestjs/common/cache'
Hash: d01fed6a10d4859462d7
Time: 24111ms
Built at: 07/20/2020 11:37:08 AM
Asset      Size  Chunks                          Chunk Names
main.js  13.7 MiB    main  [emitted]        [big]  main
main.js.map  14.8 MiB    main  [emitted] [dev]         main
Entrypoint main [big] = main.js main.js.map
chunk {main} main.js, main.js.map (main) 12.7 MiB [entry] [rendered]
WARNING in ./node_modules/@nestjs/core/helpers/optional-require.js 5:39-59
Critical dependency: the request of a dependency is an expression
WARNING in ./node_modules/@nestjs/core/helpers/load-adapter.js 8:39-63
Critical dependency: the request of a dependency is an expression
WARNING in ./node_modules/mongoose/lib/index.js 11:28-64
Critical dependency: the request of a dependency is an expression
WARNING in ./node_modules/@nestjs/common/utils/load-package.util.js 8:39-59
Critical dependency: the request of a dependency is an expression
WARNING in ./node_modules/require_optional/index.js 82:18-42
Critical dependency: the request of a dependency is an expression
WARNING in ./node_modules/require_optional/index.js 90:20-44
Critical dependency: the request of a dependency is an expression
WARNING in ./node_modules/require_optional/index.js 97:35-67
Critical dependency: the request of a dependency is an expression
WARNING in ./node_modules/mongodb/lib/operations/connect.js
Module not found: Error: Can't resolve 'mongodb-client-encryption' in '/Users/jeremy/MEGA/projects/FlipIt/fullstack-flip8/node_modules/mongodb/lib/operations'
this.debug is not a function
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fullstack-flip8@0.0.0 dev:ssr: `ng run fullstack-flip8:serve-ssr`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fullstack-flip8@0.0.0 dev:ssr script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jeremy/.npm/_logs/2020-07-20T17_37_12_756Z-debug.log

我不知道它是在使用服务、HttpClient还是其他什么。

使用"修复"分支。我将进行一些故障排除测试。

我通过安装几个包(请参阅下面的(,使它在您的修复分支上运行。我看到的第一对错误是Module not found errors。不确定为什么没有安装这些软件包,或者您是否使用了一些本应安装它们的库?

npm i --save-dev mongoose
npm i --save-dev cache-manager

在安装这些之后,我能够运行ng服务而没有错误。npm run start,正如您的package.json中所述。然而,在那之后,我遇到了一个运行时错误。

bare.js:20 Uncaught ReferenceError: process is not defined
at Object../node_modules/cli-color/bare.js (bare.js:20)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/cli-color/index.js (index.js:5)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/@nestjs/common/services/logger.service.js (logger.service.js:5)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/@nestjs/common/decorators/core/set-metadata.decorator.js (set-metadata.decorator.js:3)
at __webpack_require__ (bootstrap:79)
at Object../node_modules/@nestjs/common/decorators/core/index.js (index.js:12)
at __webpack_require__ (bootstrap:79)

在谷歌上快速搜索后,我看到了这篇stackoverflow帖子:Angular 6-在尝试为应用程序提供服务时没有定义进程

将以下内容应用于polyfills.ts似乎解决了运行时问题。现在一切都在运转。我不熟悉Angular CLI的这种类型的设置。因此,可能有更好的方法来修复过程未定义错误?

(window as any).global = window;
global.Buffer = global.Buffer || require('buffer').Buffer;
global.process = require('process');

相关内容

  • 没有找到相关文章

最新更新