首页 > 解决方案 > Angular Universal“找不到模块文件(/src/app/.ts)”

问题描述

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

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

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

ng add @nguniversal/express-engine --clientProject <my project name>

我收到以下错误:

Module file (/src/app/.ts) not found

这是我得到的唯一错误,很难知道从哪里开始。我也没有在网上发现任何类似的问题。有谁知道我该如何解决这个问题?

这是 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

这也是我的 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"]
}

标签: angularangular-universal

解决方案


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

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

虽然有解决方法。您可以在from中更改AppModule导入main.ts

import {AppModule} from './app'; 

import {AppModule} from './app/app.module';

推荐阅读