ngx-rocket / generator-ngx-rocket

:rocket: Extensible Angular 14+ enterprise-grade project generator
https://ngx-rocket.github.io/
MIT License
1.53k stars 217 forks source link

Add universal Server Side Rendering error Module file (/src/@app/app.module.ts) not found #472

Closed manzapanza closed 4 years ago

manzapanza commented 5 years ago

I'm submitting a...

Current behavior

I'm follow the documentation to add universal server side rendering to the project:

Running the command:

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

The command install the package @nguniversal/express-engine but after that I get this error:

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

I tried also with a fresh new generated project with the version 6.1.0, but I get the same error.

Expected behavior

This command should install the package @nguniversal/express-engine and edit the project adding some new files and editing some others.. something like that:

Installed packages for tooling via npm.
CREATE src/main.server.ts (220 bytes)
CREATE src/app/app.server.module.ts (427 bytes)
CREATE src/tsconfig.server.json (219 bytes)
CREATE webpack.server.config.js (1360 bytes)
CREATE server.ts (1472 bytes)
UPDATE package.json (1874 bytes)
UPDATE angular.json (4499 bytes)
UPDATE src/main.ts (432 bytes)
UPDATE src/app/app.module.ts (438 bytes)

Minimal reproduction of the problem with instructions

mkdir my-project-name && cd $_
ngx new
...
// follow the wizard choosing any options and create the project.
// After that run:
...
ng add @nguniversal/express-engine --clientProject my-project-name
Installed packages for tooling via npm.
Module file (/src/@app/app.module.ts) not found

Environment

- generator version: 6.1.0
- node version: 10.4.1
- npm version: 6.1.0
- OS:  Mac
sinedied commented 5 years ago

Seems more like a ng-cli issue with that particular generator that our own, as the expected path (/src/@app) vs (src/app) is not derived properly from angular.json config.

If it's just a path (app vs @app) issue, that could be an easy fix we can do anyways.

See also https://github.com/ngx-rocket/generator-ngx-rocket/issues/230 for reference as Angular universal may not be supported yet.

benja-admin commented 5 years ago

"If it's just a path (app vs @app) issue, that could be an easy fix we can do anyways."

This is exactly what my issue is. Did we have a resolution on this?

sinedied commented 5 years ago

I tried with a plain app coming from ng new and they have the exact same path structure.

Seems to me that the problems comes from the @nguniversal/express-engine schematics that do not properly takes in account the typescript path alias @app set in tsconfig.json, causing this failure. Unfortunately, I see nothing that we can do on our side, you should try posting this issue to the @nguniversal/express-engine repo.

In the meantime, you can try substituting @app/ imports in your apps with full absolute paths (ie /src/app) and remove the alias from tsconfig.json.

imomin commented 5 years ago

I updated import { AppModule } from '@app/app.module'; to import { AppModule } from './app/app.module'; in my main.ts. After install, I switched it back.

reza-iranmanesh commented 5 years ago

I had a very similar problem, documented here and @imomin 's answer worked.

sinedied commented 4 years ago

Closing as the issue should be moved to @nguniversal/express-engine repo.