nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.29k stars 2.32k forks source link

Importing libs from different workspace #381

Closed piernik closed 6 years ago

piernik commented 6 years ago

I created two workspaces my-app and my-utils. my-utils is workspace with libs to use in multiple workspaces.

What I have to do to be able to use libs from different workspace?

In my-app I changed paths propetry in tsconfig.json and added relative path to my-utils libs folder:

"paths": {
  "@my-app/*": [
    "libs/*"
  ],
  "@utils/*": [
    "../../libsNg/utils/libs/*"
  ]
}

When I import simpliest component (without injected services) it works, but for example this component generates error No provider for ElementRef!:

import {Component, ElementRef, OnInit} from '@angular/core';

@Component({
  selector: 'first-test',
  templateUrl: './first-test.component.html',
  styleUrls: ['./first-test.component.css']
})
export class FirstTestComponent implements OnInit {

  constructor(protected eleRef:ElementRef) { }

  ngOnInit() {
  }

}

What I'm doing worng?

Both workspaces are generated with newwest version of nx

jeffbcross commented 6 years ago

My guess is you're ending up with two instances of Angular package being installed, and at runtime you have two different ElementRef symbols, one of which isn't known by the injector. @vsavkin has written an article on how to leverage yarn workspaces with multiple Nx workspaces: https://blog.nrwl.io/dev-workflow-using-git-submodules-and-yarn-workspaces-14fd06c07964

piernik commented 6 years ago

I use npm :/ In @utils libs are only ts files - no tsconfig, package and so on. So it does not know of different @angular files.

But I think it is an angular-cli bug: https://github.com/angular/angular-cli/issues/10031

Can I manually change version of @angular/cli in package file?

demisx commented 4 years ago

Is it a best practice to import modules from another workspace or should workspaces be isolated?

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.