运行我的应用程序时为什么会出现此错误,“ ./ node_modules/@nestjs/common/cache/cache.providers.js中的错误”?

时间:2020-07-20 18:07:26

标签: javascript angular angular-cli nestjs angular-universal

设置应用非常容易。我刚刚用“ ng new [app name]”创建了它。我添加了棱角分明的材料。我还通过'ng add @ nestjs / ng-universal添加了Nestjs的Angular Univeral服务器。我了解到我需要确保没有使用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或其他东西。

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

1 个答案:

答案 0 :(得分:0)

我可以通过安装几个软件包使它在您的fix分支上运行(请参见下文)。我看到的前几个错误是Module not found errors。不确定为什么未安装这些软件包,或者您是否正在使用应该安装这些软件包的某些库?

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

安装这些文件后,我能够无错误运行ng serve。 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)

在Google快速搜索后,我遇到了以下这个stackoverflow帖子:Angular 6 - process is not defined when trying to serve application

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

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