Angular универсальный имеет ошибку на express и не может работать - PullRequest
1 голос
/ 02 мая 2020

Я пытаюсь использовать Angular универсальный для моего проекта, но я столкнулся с некоторой проблемой, и ниже подробно

1. нг - версия

Angular CLI: 9.0.2
Node: 13.5.0
OS: win32 x64

Angular: 9.0.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.900.2
@angular-devkit/build-angular      0.900.7
@angular-devkit/build-optimizer    0.900.7
@angular-devkit/build-webpack      0.900.7
@angular-devkit/core               9.0.2
@angular-devkit/schematics         9.0.2
@angular/cdk                       9.0.0
@angular/cli                       9.0.2
@angular/localize                  9.0.5
@angular/material                  9.0.0
@angular/material-moment-adapter   9.0.0
@angular/platform-server           9.0.7
@ngtools/webpack                   9.0.7
@nguniversal/builders              9.1.0
@nguniversal/common                9.1.0
@nguniversal/express-engine        9.1.0
@schematics/angular                9.0.2
@schematics/update                 0.900.2
rxjs                               6.5.4
typescript                         3.7.5
webpack                            4.41.6

2. npm run dev: ssr (server.ts имеет ошибку в express функция: "const server = express ();")

Hash: 31de884421a0ec6deaeb
Time: 39355ms
Built at: 05/02/2020 11:20:23 AM
      Asset      Size  Chunks         Chunk Names
    main.js  4.08 KiB    main         main
main.js.map   3.5 KiB    main  [dev]  main
Entrypoint main = main.js main.js.map
chunk {main} main.js, main.js.map (main) 28 bytes [entry] [rendered]

ERROR in server.ts:13:18 - error TS2349: This expression is not callable.
  Type 'typeof e' has no call signatures.

13   const server = express();
                    ~~~~~~~
  server.ts:4:1
    4 import * as express from 'express';
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.


chunk {main} main.js, main.js.map (main) 3.13 MB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 148 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 86.1 kB [entry] [rendered]
chunk {styles} styles.css, styles.css.map (styles) 438 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 9.61 MB [initial] [rendered]
Date: 2020-05-02T04:20:45.807Z - Hash: 07ffd3421b26b0f8711d - Time: 53740ms
this.debug is not a function

3 , устранить ошибку на express, используя "import express from 'express';" вместо "import * as express from 'express" "

Date: 2020-05-02T04:25:47.562Z - Hash: 07ffd3421b26b0f8711d - Time: 90330ms
Compiled successfully.
D:\AngularProjects\helloj
obclient\dist\hellojobclient\server\main.js:19052
            window.addEventListener('test', (/** @type {?} */ (null)), Object.defineProperty({}, 'passive', {
                   ^

TypeError: window.addEventListener is not a function
    at supportsPassiveEventListeners (D:\AngularProjects\hellojobclient\dist\hellojobclient\server\main.js:19052:20)
    at normalizePassiveListenerOptions (D:\AngularProjects\hellojobclient\dist\hellojobclient\server\main.js:19073:12)
    at Module../node_modules/@angular/material/__ivy_ngcc__/fesm2015/tooltip.js (D:\AngularProjects\hellojobclient\dist\hellojobclient\server\main.js:153609:125)
    at __webpack_require__ (D:\AngularProjects\hellojobclient\dist\hellojobclient\server\main.js:20:30)
    at Object../src/app/verified/history-recruitment/history-recruitment.component.ts (D:\AngularProjects\hellojobclient\dist\hellojobclient\server\main.js:336514:33)
    at __webpack_require__ (D:\AngularProjects\hellojobclient\dist\hellojobclient\server\main.js:20:30)
    at Object../src/app/app.routes.ts (D:\Ang
ularProjects\hellojobclient\dist\hellojobclient\server\main.js:303743:41)
    at __webpack_require__ (D:\AngularProjects\hellojobclient\dist\hellojobclient\server\main.js:20:30)
    at Object../src/app/shared/shared.module.ts (D:\AngularProjects\hellojobclient\dist\hellojobclient\server\main.js:332543:22)
    at __webpack_require__ (D:\AngularProjects\hellojobclient\dist\hellojobclient\server\main.js:20:30)

A server error has occurred.
node exited with 1 code.
connect ECONNREFUSED 127.0.0.1:58315

После обнаружения этой ошибки я пытаюсь разрешить по коду комментария, следуя за ошибкой отслеживания, но гораздо больше времени сталкиваюсь с другими ошибками

...