Angular Universal“找不到模块文件(/src/app/.ts)”

Nyl*_*ile 8 angular-universal angular

我有一个最初在Angular 2上开发的应用程序,随着使用Angular发行文档发布新版本的Angular,我逐渐随着时间的推移而迁移。目前,应用程序中的angular版本为:7.2.15

我还应该补充一点,我已经使用@ nrwl / nx将NestJs + Angular项目移动到了单声道存储库中,但是即使尝试在不使用@ nrwl / nx的单声道存储库中将通用添加到我以前的版本中,也会出现相同的错误

现在,当我尝试添加角度通用支持时:

ng add @nguniversal/express-engine --clientProject <my project name>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Module file (/src/app/.ts) not found
Run Code Online (Sandbox Code Playgroud)

这是我遇到的唯一错误,因此很难知道从哪里开始。我也找不到在线报告任何类似的问题。有人知道我该如何解决?

这是ng -v的输出:

Your global Angular CLI version (8.2.0) is greater than your local
version (7.3.9). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / ? \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.3.9
Node: 10.16.0
OS: darwin x64
Angular: 7.2.15
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.8.9
@angular-devkit/build-angular     0.8.9
@angular-devkit/build-optimizer   0.8.9
@angular-devkit/build-webpack     0.8.9
@angular-devkit/core              0.8.9
@angular-devkit/schematics        7.3.9
@angular/cdk                      7.3.7
@angular/cli                      7.3.9
@ngtools/webpack                  6.2.9
@schematics/angular               7.3.9
@schematics/update                0.13.9
rxjs                              6.2.2
typescript                        3.2.4
webpack                           4.16.4

Run Code Online (Sandbox Code Playgroud)

这也是我的tsconfig.json:

{
    "compileOnSave": false,
    "compilerOptions": {
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "importHelpers": true,
        "target": "es5",
        "module": "es2015",
        "typeRoots": ["node_modules/@types"],
        "lib": ["es2017", "dom"],
        "skipLibCheck": true,
        "skipDefaultLibCheck": true,
        "baseUrl": ".",
        "paths": {
            "@app/api-interface": ["libs/api-interface/src/index.ts"],
            "@app/shared-lib": ["libs/shared-lib/src/index.ts"]
        }
    },
    "exclude": ["node_modules", "tmp"]
}
Run Code Online (Sandbox Code Playgroud)

Tar*_*ani 13

其他用户也报告了该问题。你可以看到下面的github线程

https://github.com/ngx-rocket/generator-ngx-rocket/issues/472#issuecomment-512598966

不过有解决方法。您可以AppModulemain.tsfrom 中更改导入

import {AppModule} from './app'; 
Run Code Online (Sandbox Code Playgroud)

import {AppModule} from './app/app.module';
Run Code Online (Sandbox Code Playgroud)

  • 就我而言,我必须将“@app/app.module”更改为“./app/app.module”。只是为了让别人注意到:) (3认同)

Saj*_*ran 0

它看起来很奇怪,因为错误中显示的模块文件完全不相关,您可以尝试将以下内容添加到我的 tsconfig.json 文件中吗

"moduleResolution": "node",
Run Code Online (Sandbox Code Playgroud)