Skip to content

Cannot find module 'shared' when building a nested project that imports a shared library #14208

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

Closed
christofferfleat opened this issue Apr 18, 2019 · 2 comments

Comments

@christofferfleat
Copy link

christofferfleat commented Apr 18, 2019

🐞 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?

Not sure.

Description

I'm trying to implement Universal with a project structure like:

workspace
  projects
    foo
    shared
      lib
       shared.service.ts
      public_api.ts <!-- this exports the shared.service.ts
  src
  ...

I ran ng add @nguniversal/express-engine --clientProject foo standing in workspace and it added all the files it should. Here's where I stumbled upon two issues:

  1. Running npm run build:ssr && npm run serve:ssr directly after the previous command results in it building the workspace project instead of projects/foo which was specified as the --clientProject.

I changed the following line:

"build:client-and-server-bundles": "ng build --prod && ng run foo:server:production"

To:

"build:client-and-server-bundles": "ng build foo --prod && ng run foo:server:production"

And it builds the correct project, this should be default behaviour shouldn't it?

  1. In the foo project I'm importing things from shared, but these imports doesn't work when I run npm run build:ssr && npm run serve:ssr. All I get is:
projects/foo/src/app/app.component.ts(3,34): error TS2307: Cannot find module 'shared'.

This is strange to me since the library works great when just serving the foo project normally.

🔬 Minimal Reproduction

Repo found here: https://github.com/chrillewoodz/universal-library-repro

$ ng new workspace
$ cd workspace
$ ng generate application foo
$ ng add @nguniversal/express-engine --clientProject foo
$ ng generate library shared
$ ng build shared

Add import {SharedService} from 'shared'; to projects/foo/src/app/app.component.ts.

Change package.json line 14 to:

"build:client-and-server-bundles": "ng build foo --prod && ng run foo:server:production"

Run npm run build:ssr && npm run serve:ssr.

🔥 Exception or Error


ERROR in projects/foo/src/app/app.component.ts(3,29): error TS2307: Cannot find module 'shared'.

🌍 Your Environment


Angular CLI: 7.0.7
Node: 8.12.0
OS: darwin x64
Angular: 7.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.10.7
@angular-devkit/build-angular      0.10.7
@angular-devkit/build-ng-packagr   0.10.7
@angular-devkit/build-optimizer    0.10.7
@angular-devkit/build-webpack      0.10.7
@angular-devkit/core               7.0.7
@angular-devkit/schematics         7.0.7
@angular/cli                       7.0.7
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.0.7
@schematics/angular                7.0.7
@schematics/update                 0.10.7
ng-packagr                         4.7.1
rxjs                               6.3.3
typescript                         3.1.6
webpack                            4.19.1
@alan-agius4
Copy link
Collaborator

Duplicate of #13935

You need to remove the baseUrl from the server tsconfig
https://github.com/chrillewoodz/universal-library-repro/blob/master/projects/foo/tsconfig.server.json#L5

@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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants