Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng add @nguniversal/express-engine doesn't work with lib #13935

Closed
robertIsaac opened this issue Mar 16, 2019 · 2 comments · Fixed by #13938
Closed

ng add @nguniversal/express-engine doesn't work with lib #13935

robertIsaac opened this issue Mar 16, 2019 · 2 comments · Fixed by #13938
Labels
area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Milestone

Comments

@robertIsaac
Copy link

🐞 Bug report

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [x] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

no

Description

running ng add @nguniversal/express-engine --clientProject projectName generates tsconfig.server.json which has "baseUrl": "." that broke the paths from the parent tsconfig.json
the paths option is used when generating a library so that the project reads the complied code from dist and works normally

🔬 Minimal Reproduction

Reproduction repo
https://github.com/robertIsaac/ng-lib-ssr
generated as followed

ng new lib-ssr // commit #1 initial commit
cd lib-ssr // works fine from localhost:4200
ng add @nguniversal/express-engine --clientProject lib-ssr // commit #2 add ssr
npm run build:ssr && npm run serve:ssr // works fine from localhost:4000
ng g library lib // commit #3 add lib
ng b lib // build the library to start using it
// import LibModule from app.module and use <lib-lib> compoennt in app.compoennt 
// commit #4 "use lib component inside the project"
npm start // works fine from lcoalhost:4200 and shows "lib works!"
npm run build:ssr && npm run serve:ssr or just ng run lib-ssr:server:production // will throw the error

🔥 Exception or Error


ERROR in src\app\app.module.ts(13,5): Error during template compile of 'AppModule'
  Could not resolve lib relative to [object Object]..
src/app/app.module.ts(5,25): error TS2307: Cannot find module 'lib'.

🌍 Your Environment


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


Angular CLI: 7.3.6
Node: 11.11.0
OS: win32 x64
Angular: 7.2.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.13.6
@angular-devkit/build-angular      0.13.6
@angular-devkit/build-ng-packagr   0.13.6
@angular-devkit/build-optimizer    0.13.6
@angular-devkit/build-webpack      0.13.6
@angular-devkit/core               7.3.6
@angular-devkit/schematics         7.3.6
@angular/cli                       7.3.6
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.3.6
@schematics/angular                7.3.6
@schematics/update                 0.13.6
ng-packagr                         4.7.1
rxjs                               6.3.3
typescript                         3.2.4
webpack                            4.29.0

Anything else relevant?
solving the problem is to edit src/tsconfig.server.json and remove "baseUrl": "." from compilerOptions
or add

    "paths": {
      "lib": [
        "../dist/lib"
      ],
      "lib/*": [
        "../dist/lib/*"
      ]
    }

to the compilerOptions

but the latter refer to lib-ssr/out-tsc as tsc output so you may consider changing the outDir to ../dist/out-tsc/app-server so that it refer lib-ssr/dist/out-tsc as it suppose to but i'm not sure if it will matter at all

@alan-agius4 alan-agius4 added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity3: broken area: @schematics/angular labels Mar 18, 2019
@ngbot ngbot bot added this to the Backlog milestone Mar 18, 2019
@alan-agius4
Copy link
Collaborator

@robertIsaac, removing the baseUrl from the server tsconfig, is the correct approach.

alexeagle pushed a commit that referenced this issue Mar 19, 2019
The baseUrl is used for non relative module imports, and we should always use the baseUrl set in the workspace tsconfig. When having path mappings set at workspace level and setting a `baseUrl` in the server tsconfig, this paths will no longer work as paths mapping as relative to the baseUrl.

Fixes #13935
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants