14

I have an app originally developed on Angular 2 that I have slowly migrated over time as new versions of Angular come out using Angular release documentations. Currently the version of the angular in the app is: 7.2.15

I should also add that I have moved my NestJs + Angular projects into a mono repo using: @nrwl/nx, but even trying to add universal to my previous versioin with no @nrwl/nx mono-repo is giving the same error

Now when I try to add angular universal support:

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

I am getting the following error:

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

This is the only error I am getting, making it very difficult to know where to start. I do not find any similar issue being reported online either. Anybody knows how I can resolve this?

Here is the output of 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

Also here is my 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"]
}
Nylon Smile
  • 8,990
  • 1
  • 25
  • 34
  • Have you try to upgrade to angular v8 ? It seems you using `CLI` v8 but Angular `v7` – Martin Choraine Aug 09 '19 at 14:48
  • 1
    Do you have a repo which one can try this on? – Tarun Lalwani Aug 12 '19 at 15:58
  • Does anything happen if you change your baseUrl to "./"? – Mickers Aug 12 '19 at 17:33
  • @Mickers made no difference – Nylon Smile Aug 12 '19 at 18:13
  • @TarunLalwani , not sure how I can do it, the project is huge. But I can provide any file/configs that you think might be relevant. – Nylon Smile Aug 12 '19 at 18:14
  • See if this helps? https://github.com/ngx-rocket/generator-ngx-rocket/issues/472 – Tarun Lalwani Aug 12 '19 at 18:24
  • @TarunLalwani the last comment in that github link worked (https://github.com/ngx-rocket/generator-ngx-rocket/issues/472#issuecomment-512598966). in my main.ts I had: import {AppModule} from './app'; changing it to: import {AppModule} from './app/app.module'; worked. Please convert your comment to an answer so I can assign the bounty points after the 24 hours hold period. Thank you. – Nylon Smile Aug 12 '19 at 18:33

2 Answers2

17

The issue has been reported by other users as well. You can see the below github thread

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

There is workaround though. You can change the AppModule import in your main.ts from

import {AppModule} from './app'; 

to

import {AppModule} from './app/app.module';
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • 4
    In my case I had to change `@app/app.module` to `./app/app.module`. Just for others to notice :) – illnr Feb 06 '20 at 10:10
0

It looks very strange as the module file shows in the error is completely unrelevant, can you try adding the following to my tsconfig.json file

"moduleResolution": "node",
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • above line is already in tsconfig.json. I have updated the question with the full content of tsconfig.json, also a note about @nrwl/nx – Nylon Smile Aug 08 '19 at 20:17