Skip to content

Dependencies between Apps created with angular-cli #1095

@MathieuNls

Description

@MathieuNls

I am using the Angular2-cli to create two applications: MyFirstApp & MySecondApp. I whish MySecondApp to import MyFirstApp so I can reuse directive/service/component.
When I import MyFirstApp, using the documentation for 3rd parties I have the following compilation error: Cannot find module 'MyFirstApp'.

Here's how to reproduce:

    $ npm -v
    3.9.3

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: elementary OS
    Description:    elementary OS Freya
    Release:    0.3.2
    Codename:   freya

    $ node -v
    v6.2.1

    $ npm list  | grep 'angular'
    ├── @angular/common@2.0.0-rc.1
    ├── @angular/compiler@2.0.0-rc.1
    ├── @angular/core@2.0.0-rc.1
    ├── @angular/http@2.0.0-rc.1
    ├── @angular/platform-browser@2.0.0-rc.1
    ├── @angular/platform-browser-dynamic@2.0.0-rc.1
    ├── @angular/router@2.0.0-rc.1
    ├─┬ angular-cli@1.0.0-beta.5

    $ ng new MyFirstApp
    $ cd MyFirstApp
    $ ng g service MyFirstAppService
    $ ng build
    $ cd ..
    $ ng new MySecondApp
    $ cd MySecondApp
    $ npm install ../MyFirstApp --save

Add MyFirstApp to angular-cli-build.js & system.config.ts as shown in the doc.

//angular-cli-build.js
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
      'systemjs/dist/system-polyfills.js',
      'systemjs/dist/system.src.js',
      'zone.js/dist/**/*.+(js|js.map)',
      'es6-shim/es6-shim.js',
      'reflect-metadata/**/*.+(js|js.map)',
      'rxjs/**/*.+(js|js.map)',
      'my-first-app/**/*.+(js|js.map)', //HERE
      '@angular/**/*.+(js|js.map)'
    ]
  });
};

//system.config.ts
const map: any = {
  'my-first-app': 'vendor/my-first-app/index.js'
  // Also tried  'my-first-app': 'node_modules/my-first-app/index.js'
};

/** User packages configuration. */
const packages: any = {
  'my-first-app': {
   format:'cjs'
  }
};

Then,

//my-second-app.component.ts
import * as firstapp from 'my-first-app'; // -> `Cannot find module 
import { MyFirstAppServiceService } from 'my-first-app/my-first-app-service.service'; // -> `Cannot find module 
import { MyFirstAppServiceService } from 'my-first-app/src/app/my-first-app-service.service'; //-> Works !

The last import works, but I guess it doesn't leverage angular-cli-build.js nor system-config.ts.

Note that the resulting vendors/my-first-app/ directory doesn't contain the actual code of MyFirstApp

$ # While in MySecondApp
$ tree dist/vendor/my-first-app 
dist/vendor/my-first-app
├── angular-cli-build.js
└── config
    ├── environment.js
    ├── karma.conf.js
    ├── karma-test-shim.js
    └── protractor.conf.js

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions