Git Product home page Git Product logo

generator-angular2-library's Introduction

generator-angular-2-library NPM version Build Status

Yeoman generator to create a standalone Angular library in seconds.

If you want to create an Angular library with directives, services and/or pipes, then this generator is just what you need.

This generator aligns with the official Angular Package Format and automatically generates a Flat ES Module, a UMD bundle, a single metadata.json and type definitions to make your library ready for AOT compilation by the consuming Angular application.

Watch Jason Aden's talk to learn more about the Angular Package Format.

More specifically, the latest version of this generator:

  • supports Angular 5
  • creates and configures package.json for the development of your library
  • creates and configures a second package.json for the distribution of your library
  • creates and configures tsconfig.json for your editor during development
  • creates and configures tslint.json for linting purposes
  • creates and configures .gitignore, .npmignore and .travis.yml
  • creates the main library file, a sample directive, a sample component, a sample service and a sample pipe
  • configures tslint for you with codelyzer support
  • creates and configures build scripts to generate a Flat ES Module (FESM), type definitions and metadata files for your library to make it ready for AOT compilation
  • creates and configures build scripts to generate a Universal Module Definition (UMD) bundle to use your library in Node.js, SystemJS and with script tags (Plunker, Fiddle, etc)
  • inlines templates automatically for you so you can use external HTML templates
  • inlines styles automatically for you so you can use external CSS templates
  • supports .scss files
  • supports unit tests and code coverage using jest

This generator is built for Angular version 2 and above, hence the name generator-angular2-library. If you are looking for a similar generator for AngularJS 1.x, please visit generator-angularjs-library.

Quick start

generator-angular2-library-v10

First, install Yeoman and generator-angular2-library using npm (assuming you already have node.js pre-installed).

$ npm install -g yo
$ npm install -g generator-angular2-library

make a new directory and cd into it:

$ mkdir angular-library-name
$ cd angular-library-name

and generate your new library:

$ yo angular2-library

The generator will prompt you for:

? Your full name: Jurgen Van de Moere
? Your email address: [email protected]
? Your library name (kebab case): angular-library-name
? Git repository url: https://github.com/jvandemo/angular2-library-name

and create the following files for you:

.
├── README.MD
├── gulpfile.js
├── package.json
├── src
│   ├── index.ts
│   ├── package.json
│   ├── sample.component.ts
│   ├── sample.directive.ts
│   ├── sample.pipe.ts
│   ├── sample.service.ts
│   └── tsconfig.es5.json
├── tsconfig.json
└── tslint.json

You can then add or edit *.ts files in the src/ directory and run:

$ npm run build

to automatically create all *.js, *.d.ts and *.metadata.json files in the dist directory:

dist
├── index.d.ts                  # Typings for AOT compilation
├── index.js                    # Flat ES Module (FESM) for use with webpack
├── lib.d.ts                    # Typings for AOT compilation
├── lib.metadata.json           # Metadata for AOT compilation
├── lib.umd.js                  # UMD bundle for use with Node.js, SystemJS or script tag
├── package.json                # package.json for consumer of your library
├── sample.component.d.ts       # Typings for AOT compilation
├── sample.directive.d.ts       # Typings for AOT compilation
├── sample.pipe.d.ts            # Typings for AOT compilation
└── sample.service.d.ts         # Typings for AOT compilation

Finally you publish your library to NPM by publishing the contents of the dist directory:

$ npm publish dist

TypeScript config

The generator creates 2 TypeScript config files:

  • tsconfig.json is used to configure your editor during development and is not used for building your library
  • src/tsconfig.es5.json is used by the Angular compiler to build the files in the dist directory when you run npm run build

Linting your code

Your library comes pre-configured with tslint and codelyzer support. To lint your code:

$ npm run lint

Building your library

From the root of your library directory, run:

$ npm run build

This will generate a dist directory with:

  • a package.json file specifically for distribution with Angular listed in the peerDependencies
  • sample-library.js: a Flat ES Module (FESM) file that contains all your library code in a single file
  • sample-library.umd.js: a Universal Module Definition (UMD) bundle file that contains all your library code in UMD format for use in Node.js, SystemJS or via a script tag (e.g. in Plunker, Fiddle, etc)
  • *.d.ts: type definitions for you library
  • sample-library.metadata.json: metadata for your library to support AOT compilation

Generating documentation for your library

From the root of your library directory, run:

$ npm run docs:build

This will generate a docs directory with all documentation of your library.

To serve your documentation, run:

$ npm run docs:serve

and navigate your browser to http://localhost:8080.

To automatically rebuild your documentation every time a file in the src directory changes, run:

$ npm run docs:watch

For more features, check out the compodoc website.

Publishing your library to NPM

To publish your library to NPM, first generate the dist directory:

$ npm run build

and then publish the contents of the dist directory to NPM:

$ npm publish dist

Consuming your library

Once you have published your library to the NPM registry, you can import it in any Angular application by first installing it using NPM:

$ npm install sample-library # use the name you used to publish to npm

and then importing your library in your Angular AppModule (or whatever module you wish to import your library into):

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import your library
import { SampleModule } from 'sample-library';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    
    // Specify your library as an import
    SampleModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Once your shared library is imported, you can use its components, directives and pipes in your Angular application templates:

<!-- app.component.html -->
<h1>{{ title }}</h1>
<sample-component>
  This component is part of the shared library and will now work as expected.
</sample-component>

and if you need to access a service from your shared library, you can inject it using Dependency Injection:

import { Component } from '@angular/core';

// Import the shared service
import { SampleService } from 'sample-library';

@Component({
  template: 'Injecting a service from the shared library'
})
export class HomeComponent {

  // Inject the service using Angular DI 
  constructor(private sampleService: SampleService){
  
  }

}

To learn more about Angular Dependency Injection, check out the Official Angular Documentation.

Preview your library during development

To preview your library code during development, start the playground:

$ npm run playground

Changes to your library code will be updated live in the browser window:

playground

Consuming your library in a local application during development

To consume your library in a local application before you publish it to npm, you can follow the following steps:

  1. Create your library:
$ yo angular2-library

Let's assume you name your library sample-library.

  1. Navigate to the sample-library directory:
$ cd sample-library
  1. Compile your library files:
$ npm run build
  1. From the sample-library/dist directory, create a symlink in the global node_modules directory to the dist directory of your library:
$ cd dist
$ npm link
  1. Create a new Angular app. Let's assume you use angular-cli:
$ cd /your-projects-path
$ ng new my-app
  1. Navigate to the my-app directory:
$ cd my-app
  1. From the my-app directory, link the global sample-library directory to node_modules of the my-app directory:
$ npm link sample-library
  1. Import SampleModule in your Angular application:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import your library
import { SampleModule } from 'sample-library';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    
    // Specify your library as an import
    SampleModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  1. Once your shared library is imported, you can use its components, directives and pipes in your Angular application templates:
<!-- app.component.html -->
<h1>{{ title }}</h1>
<sample-component>
  This component is part of the shared library and will now work as expected.
</sample-component>

and if you need to access a service from your shared library, you can inject it using Dependency Injection:

import { Component } from '@angular/core';

// Import the shared service
import { SampleService } from 'sample-library';

@Component({
  template: 'Injecting a service from the shared library'
})
export class HomeComponent {

  // Inject the service using Angular DI 
  constructor(private sampleService: SampleService){
  
  }

}
  1. When you make a change to your library, recompile your library files again from your sample-library directory:
$ npm run build
  1. If you want to automatically recompile the library files when a file in src changes, run
$ npm run build:watch
  1. If you are using an Angular CLI application to consume your library, make sure to set up a path mapping in /src/tsconfig.app.json of your consuming application (not your library):
{
  "compilerOptions": {
    // ...
    // Note: these paths are relative to `baseUrl` path.
    "paths": {
      "@angular/*": [
        "../node_modules/@angular/*"
      ]
    }
  }
}

When you npm link a library with peer dependencies, the consuming application searches for the peer dependencies in the library's parent directories instead of the application's parent directories.

If you get Error: Unexpected value '[object Object]' imported by the module 'AppModule'. Please add a @NgModule annotation., then try:

$ ng serve --preserve-symlinks

to make sure the consuming application searches for the peer dependencies in the application's node_modules directory.

Frequently asked questions

How can I configure Karma?

Currently, the generator does not create a custom Karma configuration for running unit tests.

If your library requires a custom Karma setup, please check out this tutorial on how to configure Karma for your library (Credits to Raphael).

As soon as official recommendations are available on how to set up Karma for testing libraries, this generator will be updated accordingly.

How can I use a scoped package name?

First update the package name in src/package.json:

"name": "@scope/library-name"

and then also update flatModuleId in src/tsconfig.es5.json accordingly:

"flatModuleId": "@scope/library-name"

See #75 for more information.

How can I avoid recompilation during development

If you experience issues (#72) or want to avoid constant recompilation of your library during development, you can also npm link src instead of npm link dist in step 4 of the process above.

This will let you consume the TypeScript code directly from the src directory of your library instead of the generated bundle from the dist directory. This increases development speed if you are testing your library in a local Angular application, but remember to test the generated bundle using npm link dist after you finish writing your code, to ensure that your generated bundle is working as expected before you publish your library to NPM.

How can I use .scss files?

Simply store your styles in a file with a filename extension of scss and reference it in your component's styleUrls property.

So if you have a sample.component.scss:

h1 {
  color: red;
}

then reference it in your component's styleUrls in sample.component.ts accordingly:

@Component({
  selector: 'sample-component',
  template: `<h1>Sample component</h1>`,
  styleUrls: [
    'sample.component.scss'
  ]
})

The .scss files will automatically be compiled and inlined in your library bundle.

How can I import .scss files

To import a .scss file in an existing .scss file, you can specify a relative path:

@import '../relative/path/to/other.scss';

or use a tilde to import a file from the nearest parent node_modules directory:

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

How can I see which version of the generator I have installed

From the command line, run:

$ npm ls -g --depth=1 2>/dev/null | grep generator-

How can I update my generator to the latest version?

From the command line, run

$ yo

and select the option Update your generators.

What if my library depends on a third party library?

If your library depends on a third party library such as Angular Material or PrimeNG, you don't have to include the third party library in your library.

Instead, you should add the third party library as a peer dependency to the peerDependencies property in src/package.json of your library:

"peerDependencies": {
  "@angular/core": "^4.0.0",
  "rxjs": "^5.1.0",
  "zone.js": "^0.8.4"
}

This causes a warning to be displayed when the consuming application runs npm install and does not have the third party library installed that your library depends on.

The generator already adds @angular/core, rxjs and zone.js as peer dependencies for you by default.

Consider the following scenario where your library depends on a third party library called "PrimeNG".

In your Angular library:

  1. run npm install primeng --save to install PrimeNG and add it as a devDependency to package.json in the root directory
  2. add PrimeNG as a peerDependency in src/package.json, NOT as dependency or devDependency (src/package.json is the package.json that is distributed with your library, so you must specify primeng as peer dependency here, NOT in the package.json file in the root of your library)
  3. import the necessary PrimeNG Angular module(s) in your library Angular module
  4. write code that uses PrimeNG components
  5. build your library and publish it (or link it locally)

In the consuming Angular application

  1. run npm install yourlibrary to install your library (which should display a warning if PrimeNG is not installed) or link it locally
  2. run npm install primeng to install PrimeNG if it is not installed yet
  3. import the necessary PrimeNG Angular module(s) in your Angular application module (usually AppModule) (this step is not needed if your library exports the PrimeNG module(s) in its module metadata)
  4. import your library module in your Angular application module (usually AppModule)
  5. you can now use your library components

To see a fully documented example, check out this guide.

How can I upgrade my library to support Angular 5

Version 12 or later of this generator supports Angular 5.

If you have an existing library that was generated with an earlier version of this generator:

  1. update the versions of the Angular packages in package.json to Angular 5 (example)
  2. replace the ngc script in your gulpfile.js with:
gulp.task('ngc', function () {
  ngc([ '--project', `${tmpFolder}/tsconfig.es5.json` ]);
  return Promise.resolve()
});

See #230 for more information.

Issues

Please report bugs and issues here.

Development

To run the generator unit tests:

$ npm run test

License

MIT © Jurgen Van de Moere

Change log

v12.4.1

v12.4.0

v12.3.0

v12.2.1

  • Update system.js config to use single quotes

v12.2.0

  • Added default extension to playground system.js config to fix #146

v12.1.0

v12.0.0

  • Updated packages to Angular 5
  • Updated ngc gulp script (See #230) (Credits to Filip Lauc)

v11.4.0

  • Updated rollup and gulp-rollup configuration (See #190) (Credits to Daniel Geri)

v11.3.0

v11.2.0

  • Added guide on how depend on third party library (See #172) (Credits to Ka Tam)

v11.1.0

  • Added main and jsnext:main properties to package.json

v11.0.3

  • Added FAQ on how to add third party library
  • Updated jest support (See #91) (Credits to Fabrizio Fortunato)

v11.0.2

v11.0.1

  • Updated styleUrls to fix #140

v11.0.0

v10.2.2

v10.2.1

  • Allow real files in rollup to fix #105

v10.2.0

v10.1.1

  • Fix README

v10.1.0

  • Copy README to dist directory (#85) (Credits to David)

v10.0.0

  • Added support for generating UMD bundle

v9.3.0

v9.2.0

  • Added convenience scripts for generating documentation

v9.1.0

  • Added compodoc for generating documentation (#76)
  • Removed comments from TypeScript config files to allow JSON validity checks

v9.0.0

v8.2.1

  • Updated TypeScript files in gitignore

v8.2.0

  • Added build:watch script
  • Added dist folder to gitignore

v8.1.0

  • Remove prepublish script

v8.0.0

  • Update build process
  • Add support for AOT compilation

v7.0.0

  • Update to Angular 4

v6.0.0

  • Update to Yeoman 1.x

v5.6.0

  • Ignore files generated by ngc in .gitignore

v5.5.2

  • Remove obsolete files in package.json

v5.5.1

  • Add README.md to package.json so NPM registry can display it

v5.5.0

  • Update devDependencies

v5.4.0

  • Update to latest tslint and codelyzer

v5.3.0

  • Update TypeScript version to fix #41

v5.2.1

  • Fix eslint errors
  • Remove duplicate dependency

v5.2.0

  • Suggest better default library name

v5.1.0

  • Add support for AOT compilation
  • Update Angular 2 references to just Angular

v5.0.0

  • Replace typings with @types (#29)

v4.0.0

  • Remove default keyword when exporting module to fix #23

v3.0.4

  • Updated version of Codelyzer
  • Updated selector of sample component to kebab case to fix #21

v3.0.3

  • Fixed unit tests

v3.0.2

  • Fixed README.md example code

v3.0.1

  • Fixed tsconfig.json files

v3.0.0

  • Added support for NgModule

v2.2.0

  • Updated dependencies in package.json to Angular 2 final

v2.1.0

  • Updated templates to Angular 2.0.0 RC3 syntax

v2.0.0

  • Updated with file structure using src and dist directory

v1.1.1

  • Updated templates to Angular 2.0.0 RC1 syntax

v1.1.0

  • Added codelyzer support
  • Added tslint support
  • Added typings support

v1.0.0

v0.6.0

  • Updated dependency versions

v0.5.0

  • Added browser.d.ts to files in tsconfig.json instead of using tripleslash (see #9)

v0.4.0

  • Added reference to Angular typings

v0.3.1

  • Removed explicit RxJS dependency

v0.3.0

  • Updated to Angular 2 beta

v0.2.0

  • Added documentation
  • Added support for PROVIDERS, DIRECTIVES and PIPES

v0.1.0

  • Added documentation
  • Added boilerplate scaffolding
  • Initial version

generator-angular2-library's People

Contributors

andrewmcwatters avatar artemsky avatar beeman avatar bersling avatar caroso1222 avatar danielgeri avatar dbfannin avatar deblockt avatar gabwh avatar iamartyom avatar izifortune avatar jdjuan avatar jvandemo avatar kktam avatar lamstutz avatar manfredsteyer avatar markpieszak avatar msarsha avatar nathanwalker avatar p1p3 avatar patrickjs avatar rsginer avatar rtrompier avatar samverschueren avatar splaktar avatar tonysamperi avatar wittlock avatar zgabievi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

generator-angular2-library's Issues

Remove @types/protractor

Per my npm install...

npm WARN deprecated @types/[email protected]: This is a stub types definition for Protractor (https://github.com/angular/protractor). Protractor provides its own type definitions, so you don't need @types/protractor installed!

I can look into it later but it may involve some other upgrades too. Anyone know if the tsLint issues that prevent people from upgrading have been resolved?

Update to `[email protected]`

I noticed you are still using [email protected]. Nothing wrong with that, but not a long time ago, Yeoman released version 1.x of yeoman-generator.

An example of a generator using that is generator-nm. Since that version, you can use a class instead of an object which usually gives cleaner code.

I'm open for doing a PR if you want. Just let me know.

version 5 is not published to NPM

I was having issues with npm install on generated library related to 'postinstall typings'.
I saw there was a pull request related and noticed version 5 was released, but on npm the latest version is 4.
"4.0.0 is the latest of 18 releases"

I will install from GitHub, but I spent some time figuring our this was my issue - so if someone is having issues with post install typings that's the reason.

Unexpected value 'SamplePipe' declared by the module 'AppModule'

When working on new Angular2.0 project (check project's package.json), it gives the error:

Unexpected value 'SamplePipe' declared by the module 'AppModule'

Project's dependencies:

"dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "core-js": "^2.4.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "angular-cli": "1.0.0-beta.15",
    "codelyzer": "~0.0.26",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.5",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "2.0.2"
  }

App Module's code:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { PROVIDERS, PIPES } from 'new-library';
@NgModule({
  declarations: [
    AppComponent,
    PIPES
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [PROVIDERS],
  bootstrap: [AppComponent]
})
export class AppModule { }

I didn't change anything in the files that were generated using the generators. Just used "npm link" to register locally, and then linked to the test project to test the library in development environment.

Getting error when TSC is run

I am following the directions, however, when it runs tsc I see node_modules/@types/jasmine/index.d.ts(39,52): error TS1005: '=' expected.. Is it using an older version of the type or something?

<package-name> has no exported member SampleModule

First of all thanks for creating this project!

I'm trying to create a library that has a few components. Using version 3.0.4 of this generator I've created my library. When I try to include the library in my application I get an error:

Module '"/path/to/angular-sample-app/node_modules/angular-sample-module/dist/index"' 
has no exported member 'SampleModule'.

The fix for this is quite simple, changing export default class SampleModule to export class SampleModule makes it work.

I was wondering if this is expected behavior or if the generator should actually export the class without it being default?

If the latter is the case, please consider my PR. Thanks!

Error when using npm link into an angular-cli project

Currently a freshly generated project causes the following error when using npm link to test the library within a local angular-cli project;

ERROR in Error encountered resolving symbol values statically. Calling function 'ɵmakeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol NgModule in /path/to/project/node_modules/library-name/node_modules/@angular/core/core.d.ts, resolving symbol SampleModule in /path/to/project/node_modules/library-name/index.ts, resolving symbol SampleModule in /path/to/project/node_modules/library-name/index.ts

I've dealt with this same problem in a separate library component I have (that does not use this generator) and the solution was to move the @angular/* dependencies from dependencies to peerDependencies in package.json (as here) as it causes some bizarre errors (I believe in TypeScript). I don't know if this is something you want to deal with?

Generator fails on typings install

typings install

typings ERR! message https://api.typings.org/entries/dt/es6-shim/tags/0.31.2%2B20160317120654 responded with 401, expected it to equal 200

typings ERR! cwd /Users/e041115/dev/ess-ux-components
typings ERR! system Darwin 14.5.0
typings ERR! command "/usr/local/Cellar/node5/5.11.1/bin/node" "/Users/e041115/dev/ess-ux-components/node_modules/.bin/typings" "install"
typings ERR! node -v v5.11.1
typings ERR! typings -v 1.3.0
typings ERR! code EINVALIDSTATUS

typings ERR! If you need help, you may report this error at:
typings ERR! https://github.com/typings/typings/issues

npm WARN @angular/[email protected] requires a peer of [email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of zone.js@^0.6.6 but none was installed.
npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/Cellar/node5/5.11.1/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v5.11.1
npm ERR! npm v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! [email protected] postinstall: typings install
npm ERR! Exit status 1

How to serve?

Hi,

I'm getting this error. How to do the development from this project?

Using ng serve cause the error. Any other alternative way?

bash-3.2$ ng serve
You have to be inside an angular-cli project in order to use the serve command.

linting fails

Two problems occur when attempting to run lint:

  1. Codelyzer fails to parse the TypeScript version properly:
/Users/JohnBrecht/dev/ng2-lib-test/node_modules/codelyzer/util/syntaxKind.js:1480
                throw new Error('Unsupported TypeScript version: ' + ts.version);
                ^
Error: Unsupported TypeScript version: 2.0.2

This can be fixed my bumping the codelyzer version in package.json to ^0.0.28.

  1. One running properly, then there is a lint failure:
    src/sample.component.ts[4, 13]: The selector of the component "SampleComponent" should be named kebab-case (https://goo.gl/mBg67Z)

Which is easily fixed by changing line 4 of sample.component.ts to read:
selector: 'sample-component',

Creating an angular2 library seed project

@jvandemo I wanted to get your thoughts on this...

I'm planning on creating an angular2 library seed project. The advantage to a seed project over a generator is you get the project tooling, build pipeline, testing support, and an out of box setup to demo the library. It also prepares the developer for publishing their library to npm with all the necessary .gitignore and .npmignore files to keep things tidy.

How does that sound? Does one already exist that you know of? Anything in particular that you think needs to be in there?

Adapting to the latest Angular Library Spec presented by Google

@jvandemo in the latest ng-conf Jason Aden from Google presented an approach to building Angular Libraries using Angular Compiler (NGC) and Rollup. More information can be found here. This is the favored way to create Angular libraries according to Stephen Fluin from the Angular Core team.

So I opened this issue to know if you have considered refactoring this generator a little bit to better align with those practices which make libraries AOT ready.

If so, we could use this issue to document the changes that need to be addressed and how contributors should be able to help. What are your thoughts?

Scoped package name and publishConfig not correct

Gday Jurgen,

thanks for this awesome generator!

We do have two small things that are currently not working as expected:

  • the publishConfig property in the package.json gets removed

it is not in the generated package.json in the dist folder, we need it to be able to publish the library in our internal sonatype nexus npm registry
{ "publishConfig": { "registry": "http://url-to-nexus-npm/" } }

  • scoped library names get replaced by kebab-case

we are currently using scopes for our libraries
"name": "@project/submodule"
In the generated package.json, the name gets transferred to kebabcase "project-submodule".
Would it be possible to leave it as it is defined in the package.json?

Thanks and kind regards
Joachim

Removing of typings

I think it would be a good idea to get rid of the usage of typings in favour of the more modern approach with node_modules/@types and e.g. a lib entry in tsconfig.json.

add /dist to .gitignore

Was wondering whether or not /dist should be ignored. I've gone through material, ngbootstrap and Ionic, which I consider some of the most relevant ng libraries out there, and all of them add /dist to the gitignore.

I don't mind opening a PR for this, just wanted to open an issue and discuss this first.

Minor Typo in Readme

Hi,
Thanks a lot for the generator!
There's a minor typo in your readme:

$ yo angular-library

should be:

$ yo angular2-library

Cheers

Error Building my library in Windows

Hi,

In Windows with a new library (only generated code) I'm getting (with npm run build):

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\myuser\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 silly lifecycle [email protected]~prebuild: no script for prebuild, continuing
7 info lifecycle [email protected]~build: [email protected]
8 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~build: PATH: C:\Users\myuser\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;D:\work\WorkspaceLabs\angular-library\node_modules\.bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\Yarn\bin;C:\Users\myuser\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\PuTTY\;C:\Program Files\dotnet\;C:\ProgramData\chocolatey\bin;C:\Program Files\OpenVPN\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\nodejs\;C:\Users\myuser\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Docker Toolbox;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\myuser\AppData\Local\Yarn\.bin;C:\Users\myuser\AppData\Roaming\npm
10 verbose lifecycle [email protected]~build: CWD: D:\work\WorkspaceLabs\angular-library
11 silly lifecycle [email protected]~build: Args: [ '/d /s /c', './build.sh' ]
12 silly lifecycle [email protected]~build: Returned: code: 1  signal: null
13 info lifecycle [email protected]~build: Failed to exec build script
14 verbose stack Error: [email protected] build: `./build.sh`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (C:\Users\myuser\AppData\Roaming\npm\node_modules\npm\lib\utils\lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:194:7)
14 verbose stack     at ChildProcess.<anonymous> (C:\Users\myuser\AppData\Roaming\npm\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:194:7)
14 verbose stack     at maybeClose (internal/child_process.js:899:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid [email protected]
16 verbose cwd D:\work\WorkspaceLabs\angular-library
17 verbose Windows_NT 10.0.14393
18 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\myuser\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
19 verbose node v7.9.0
20 verbose npm  v4.5.0
21 error code ELIFECYCLE
22 error errno 1
23 error [email protected] build: `./build.sh`
23 error Exit status 1
24 error Failed at the [email protected] build script './build.sh'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the angular-library package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     ./build.sh
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs angular-library
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls angular-library
24 error There is likely additional logging output above.
25 verbose exit [ 1, true ]

I tried several versions of nodeJS and npm but the error always happens.

The same command with the same src in a Linux environment: Bash on Ubuntu on Windows works great.

Any idea/clue about what may be causing the error in Windows?

Should we still use forRoot?

The index.ts that gets generated includes a forRoot function...

export class SampleModule {
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: SampleModule,
      providers: [SampleService]
    };
  }
}

These seem to have been deprecated in most libraries (off the top of my head D3 and AngularMaterial). Do we still want to have this be the template?

Solution wont works with html file template

I change sample componente to read HTML file template, but dist wont works. Given error

Unhandled Promise rejection: Failed to load sample.component.html

Do you have any solve?

Look the change:

@Component({ selector: 'sample-component', templateUrl: './sample.component.html' }) export class SampleComponent {}

[proposal] Remove "2" from the generated Angular[2] <- library created names

Since going forward Angular2 is just going to be called Angular, it might be best to make sure people call their libraries by that (angular-libraryname), or the other common shortcut ngx-libraryname.

http://angularjs.blogspot.com/2016/12/ok-let-me-explain-its-going-to-be.html

Should we make some quick updates to the generator so we make sure people start going that route?
Maybe even just a note to let people know about new naming conventions?

Just trying to help! :)

How can I use the use the compiled js files instead of the src files?

Hey @jvandemo , this is a great and probably the best generator for Angular 2 libraries out there. You have done a great job. So thanks.

Second, I created a package and installed in my Angular 2 web application. Now when I import it, it seems like it is loading the .ts files instead of the .js generated bundle. I guess we actually want to used the compiled files instead? Or did you meant to export the .ts files to allow the user to create one unique bundle at the end?

PS: I didn't know if I should publish the question here or in StackOverflow, if needed I can delete this issue and migrate the question there.

how to add a sass/css compiler with generator-angular2-library?

I'm using your angular app to create a library of components.
I would like to develop some components with *.sass or *.scss files and compile them in css in the "dist" folder.
I imagine the best way should be adding this option on the command line "npm run tsc".
Is it already included ?
Can I do it easily ?

NPM START

I will apologize in advance, (I'm new to node/npm) this is not an issue and more than likely a user error!

But really want to run your generator.

So ran the generator answer the questions... etc.
But when I go to "npm start" this is what I get.

`0 info it worked if it ends with ok

1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'start' ]

2 info using [email protected]
3 info using [email protected]
4 verbose stack Error: missing script: start
4 verbose stack at run (/usr/share/npm/lib/run-script.js:147:19)
4 verbose stack at /usr/share/npm/lib/run-script.js:57:5
4 verbose stack at /usr/share/npm/node_modules/read-package-json/read-json.js:345:5
4 verbose stack at checkBinReferences_ (/usr/share/npm/node_modules/read-package-json/read-json.js:309:45)
4 verbose stack at final (/usr/share/npm/node_modules/read-package-json/read-json.js:343:3)
4 verbose stack at then (/usr/share/npm/node_modules/read-package-json/read-json.js:113:5)
4 verbose stack at /usr/share/npm/node_modules/read-package-json/read-json.js:232:12
4 verbose stack at /usr/share/npm/node_modules/graceful-fs/graceful-fs.js:76:16
4 verbose stack at FSReqWrap.readFileAfterClose as oncomplete
5 verbose cwd /var/www/html/broncos
6 error Linux 4.4.0-31-generic
7 error argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
8 error node v4.2.6
9 error npm v3.5.2
10 error missing script: start
11 error If you need help, you may report this error at:
11 error https://github.com/npm/npm/issues
12 verbose exit [ 1, true ]`

For the life of me I can't figure out where the start script is?

Libraries depending on libraries and template inlining not working?

First off, thank you for the generator. It has been pretty tough figuring out exactly what the Angular community is aiming for with project configuration of libraries vs. applications.

I created two libraries (call them A and B) using this generator and an application using the angular-cli. Library A depends on B, and the library A has templateUrl specified in a number of components. When the app is built (npm run build), the templates are not included. Also, the library that depends on the other can't run through npm run build.

I'm not sure exactly which errors are caused by what problems, so I'm just going to walk through this here to see if I can get my libraries working (they've been fine up until now, but I've been using tsc and not been worrying about AoT).

Taking a step back to just Library A, if I run npm run prepublish, nothing gets inlined.
For example, one of the components in A that has a templateUrl specified, the corresponding js still says templateUrl: 'the.component.template.name.html' -- it was never in-lined.

Not knowing if this is tied to running npm run build, I tried it, but I get the following error:

Error: ENOENT: no such file or directory, open '/projects/ui-development/library-a/dist/node_modules/library-b/src/shared/base.service.metadata.json'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.writeFileSync (fs.js:1333:33)
    at MetadataWriterHost.writeMetadata (/projects/ui-development/library-a/node_modules/@angular/tsc-wrapped/src/compiler_host.js:115:22)
    at MetadataWriterHost._this.writeFile (/projects/ui-development/library-a/node_modules/@angular/tsc-wrapped/src/compiler_host.js:92:23)
    at Object.writeFile (/projects/ui-development/library-a/node_modules/typescript/lib/typescript.js:64240:132)
    at Object.writeFile (/projects/ui-development/library-a/node_modules/typescript/lib/typescript.js:9020:14)
    at printSourceFileOrBundle (/projects/ui-development/library-a/node_modules/typescript/lib/typescript.js:61204:16)
    at emitSourceFileOrBundle (/projects/ui-development/library-a/node_modules/typescript/lib/typescript.js:61155:21)
    at Object.forEachEmittedFile (/projects/ui-development/library-a/node_modules/typescript/lib/typescript.js:8986:17)
Compilation failed

It seems to be trying to open library B's base service metadata file in library-a/dist/node_modules/library-b/src/... (vs. library-a/node_modules/library-b/dist/src/...).

As for my project setup, this project's README suggests using npm link. The libraries cannot be linked because there seem to be many closed (and unresolved) issues related to the angular-cli generating applications that ultimately emit obscure errors about makeDecorator not being statically analyzable, etc. (here's one). Therefore my only solution so far has been to make my package.json dependency for the libraries point to a file path relative to the application or library:

Application's package.json

"dependencies": {
    "library-a": "../library-a"

Library A's package.json

"dependencies": {
    "library-b": "../library-b"
}

In each case, I then use npm install ... to install/refresh changes up-stream to the application.

I apologize for the rather wide net of errors, but I've been at this all day trying to unpack all these little obscure error messages. At this point I'm not sure what errors are related and which are not since all of my code runs through tsc just fine.

Issue with npm link

I am experiencing an issue with a generated ng2-library when attempting to npm link into a project using webpack. I created an ng2-library-test from the generator, and did not change any of the boilerplate code. I published the library to npm at ng2-library-test and installed it in a boilerplate project here. When I run the project all works as expected. However, when I npm link the library locally, I get errors when trying to run the project:

ERROR in ../ng2-library-test/ng2-library-test.js
Module not found: Error: Cannot resolve module 'awesome-typescript-loader' in /Users/ng2-library-test
 @ ../ng2-library-test/ng2-library-test.js 5:19-46 8:9-36

ERROR in ../ng2-library-test/ng2-library-test.js
Module not found: Error: Cannot resolve module 'awesome-typescript-loader' in /Users/ng2-library-test
 @ ../ng2-library-test/ng2-library-test.js 6:14-36 10:9-31

ERROR in ../ng2-library-test/ng2-library-test.js
Module not found: Error: Cannot resolve module 'awesome-typescript-loader' in /Users/ng2-library-test
 @ ../ng2-library-test/ng2-library-test.js 7:17-42 9:9-34

ERROR in ../ng2-library-test/ng2-library-test.ts
Module not found: Error: Cannot resolve module 'awesome-typescript-loader' in /Users/ng2-library-test
 @ ../ng2-library-test/ng2-library-test.ts 5:19-46 8:9-36

ERROR in ../ng2-library-test/ng2-library-test.ts
Module not found: Error: Cannot resolve module 'awesome-typescript-loader' in /Users/ng2-library-test
 @ ../ng2-library-test/ng2-library-test.ts 6:14-36 10:9-31

ERROR in ../ng2-library-test/ng2-library-test.ts
Module not found: Error: Cannot resolve module 'awesome-typescript-loader' in /Users/ng2-library-test
 @ ../ng2-library-test/ng2-library-test.ts 7:17-42 9:9-34

Any ideas? Have you been able to npm link with a generated library successfully?

Dash-Case vs. CamelCase

In the readme, you write

<h1>{{ title }}</h1>
<sampleComponent>
  This component is part of the shared library and will now work as expected.
</sampleComponent>

however, when I tried it out, I had to use

<h1>{{ title }}</h1>
<sample-component>
  This component is part of the shared library and will now work as expected.
</sample-component>

Is this an issue or just a misunderstanding of concepts from my side?

ES5 ts build index.js keep import

Hi,

The current build of the generator is currently keeping the import inclusion (es6) in the index.js but the webpack of my angular 4 project is not converting the libraries into es5 and if I change the tsconfig.es5.json module to commonjs I don't have all the .ts files into the index.js.

Do you have a solution for that ?

Regards,

Gaetan SENN

Generate tests for each generated piece

To make testing libs easier, we should add testing infrastructure and have the generator automatically generate generic tests for the various generated pieces.

Cannot find name 'Iterable' while using angular 4.

> npm run tsc

node_modules/@angular/core/src/change_detection/differs/iterable_differs.d.ts(15,48): error TS2304: Cannot find name 'Iterable'.

npm ERR! Darwin 16.4.0
npm ERR! argv "/Users/username/.nvm/versions/node/v7.7.3/bin/node" "/Users/username/.nvm/versions/node/v7.7.3/bin/npm" "install"
npm ERR! node v7.7.3
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] prepublish: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] prepublish script 'tsc'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the myservice-api package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tsc
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugsmyservice-api
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls myservice-api
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/username/work-place/myservice-api/npm-debug.log

Error 404 / systemjs

I try to add a generated library to Angular 2's hero projet.
https://github.com/angular/quickstart

When i run my server, (npm start) i've got an 404 error :
[1] 17.01.27 17:15:00 404 GET my-lib

I try to add :
my-lib': 'npm:my-lib
or
my-lib': 'npm:my-lib/dist

to systemjs.config.js

Provide build process for standalone bundle

A library can easily be imported using import statements.

But how can we bundle a library as a standalone file that we can e.g. include from a CDN using a <script> element?

E.g. Angular publishes:
https://code.angularjs.org/2.0.0-alpha.46/angular2.js

When looking at the source code, the last few lines in the file automatically register the library:

System.register("angular2/angular2", ["angular2/common", "angular2/core", "angular2/profile", "angular2/lifecycle_hooks", "angular2/bootstrap", "angular2/upgrade"], true, function(require, exports, module) {
  var global = System.global,
      __define = global.define;
  global.define = undefined;
  function __export(m) {
    for (var p in m)
      if (!exports.hasOwnProperty(p))
        exports[p] = m[p];
  }
  __export(require("angular2/common"));
  __export(require("angular2/core"));
  __export(require("angular2/profile"));
  __export(require("angular2/lifecycle_hooks"));
  __export(require("angular2/bootstrap"));
  __export(require("angular2/upgrade"));
  global.define = __define;
  return module.exports;
});

What is the best way to publish such a distributable library file?

Package typings file cannot contain tripleslash references

So I got my custom library wired up but I have an issue with the Reference Path.. When i compile the Typescript in the app that imports the library I get...

error TS2654: Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition.

if I delete the /// from the main Typescript file (import entry point) the error goes away but I cannot compile the Typescript in my library anymore.

How can I resolve this and keep both sides happy?

Template files are not coppied to dist folder

The template files of components are not copied to the dist folder.

It would be possible to create them there directly but this does not seem like a clean solution.

@Component({
    moduleId: module.id,
    templateUrl: require('./abc.html'), // <<-----
})
export class AbcComponent implements OnInit {

various ts errors

I got various ts errors during tsc
what am i doing wrong?

node_modules/angular2/src/core/application_ref.d.ts(83,60): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/application_ref.d.ts(83,146): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/application_ref.d.ts(96,51): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/application_ref.d.ts(96,147): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/application_ref.d.ts(133,90): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/application_ref.d.ts(171,81): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/change_detection/differs/default_keyvalue_differ.d.ts(23,15): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/change_detection/differs/default_keyvalue_differ.d.ts(25,16): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/change_detection/parser/locals.d.ts(3,14): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/change_detection/parser/locals.d.ts(4,42): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/debug/debug_node.d.ts(14,13): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/debug/debug_node.d.ts(24,17): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/debug/debug_node.d.ts(25,17): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/di/provider.d.ts(436,103): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/di/provider.d.ts(436,135): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/compiler.d.ts(12,50): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/compiler.d.ts(16,41): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(108,136): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(156,150): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(197,128): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(203,127): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(204,141): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(205,119): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/render/api.d.ts(13,13): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/render/api.d.ts(14,84): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/async.d.ts(27,33): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/async.d.ts(28,45): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/collection.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'.
node_modules/angular2/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'.
node_modules/angular2/src/facade/collection.d.ts(4,27): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(4,39): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(7,9): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(8,30): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(11,43): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(12,27): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(14,23): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(15,25): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(100,41): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/collection.d.ts(101,22): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/collection.d.ts(102,25): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/lang.d.ts(4,17): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/lang.d.ts(5,17): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/lang.d.ts(70,59): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/promise.d.ts(2,14): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(8,32): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(9,38): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(10,35): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(10,93): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(11,34): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(11,50): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(12,32): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(12,149): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(13,43): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(35,67): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(50,66): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(89,67): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(94,38): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(94,50): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(46,62): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(47,42): error TS2304: Cannot find name 'Iterator'.
node_modules/rxjs/Observable.d.ts(103,74): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(103,84): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(143,66): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(158,65): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(201,66): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(206,38): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(206,50): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/observable/ForkJoinObservable.d.ts(6,50): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/observable/ForkJoinObservable.d.ts(7,58): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/observable/FromObservable.d.ts(7,38): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/observable/FromObservable.d.ts(7,51): error TS2304: Cannot find name 'Iterator'.
node_modules/rxjs/observable/PromiseObservable.d.ts(9,31): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/observable/PromiseObservable.d.ts(10,26): error TS2304: Cannot find name 'Promise'.

I can not install lib

I did librely, than I published it, but I can not install what i did.
Does generator work?

npm install hope --save

> [email protected] install S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-zopfli
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download(403): https://node-zopfli.s3.amazonaws.com/Release/zopfli-v1.4.0-node-v48-win32-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v48 ABI) (falling back to source compile with node-gyp)
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at failNoPython (S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-gyp\lib\configure.js:449:14)
gyp ERR! stack     at S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-gyp\lib\configure.js:404:11
gyp ERR! stack     at S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-gyp\node_modules\graceful-fs\polyfills.js:264:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:123:15)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "S:\\Sources\\Applications\\prototype\\platform\\resource-management\\app\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--fallback-to-build" "--module=S:\\Sources\\Applications\\prototype\\platform\\resource-management\\app\\node_modules\\node-zopfli\\lib\\binding\\node-v48-win32-x64\\zopfli.node" "--module_name=zopfli" "--module_path=S:\\Sources\\Applications\\prototype\\platform\\resource-management\\app\\node_modules\\node-zopfli\\lib\\binding\\node-v48-win32-x64"
gyp ERR! cwd S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-zopfli
gyp ERR! node -v v6.9.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'C:\Program Files\nodejs\node.exe S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-zopfli\lib\binding\node-v48-win32-x64\zopfli.node --module_name=zopfli --module_path=S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-zopfli\lib\binding\node-v48-win32-x64' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-pre-gyp\lib\util\compile.js:83:29)
node-pre-gyp ERR! stack     at emitTwo (events.js:106:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:877:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
node-pre-gyp ERR! System Windows_NT 6.1.7601
node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "S:\\Sources\\Applications\\prototype\\platform\\resource-management\\app\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-zopfli
node-pre-gyp ERR! node -v v6.9.1
node-pre-gyp ERR! node-pre-gyp -v v0.6.31
node-pre-gyp ERR! not ok
Failed to execute 'C:\Program Files\nodejs\node.exe S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-zopfli\lib\binding\node-v48-win32-x64\zopfli.node --module_name=zopfli --module_path=S:\Sources\Applications\prototype\platform\resource-management\app\node_modules\node-zopfli\lib\binding\node-v48-win32-x64' (1)
[email protected] S:\Sources\Applications\prototype\platform\resource-management\app
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- UNMET PEER DEPENDENCY @angular/[email protected]
+-- UNMET PEER DEPENDENCY @angular/[email protected]
`-- [email protected]

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\node-zopfli):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-pre-gyp install --fallback-to-build`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

add --dry-run option to skip npm install

At times it is very useful to just generate the codebase without installing the NPM modules (since it could take a lot of time). The angular CLI has this option available.

Do you consider this feature useful for the project? If so, I could add a PR.

--dry-run (alias: -d) default value: false

Problem finding angular2 module

Hello,
When I run npm install, during the tsc execution I get this error:

TS2307: Cannot find module 'angular2/angular2'

What is the cause of this?
Sorry for open an issue for this, but I don't found nothing that works.

Thanks,
Renan.

AOT

Will it create metadata.json also so that AOT compilation does not fail.

[ts] Experimental support for decorators error

Repro steps:

  1. Scaffold an app running yo angular2-library
  2. Open it in vscode
  3. Add file hello.component.ts
  4. Add this into the file:
import { Component } from '@angular/core';

@Component({
  selector: 'app-hello',
  template: `<h1>Hello World</h1>`
})
export class HelloComponent {
  title = 'app works!';
}

Error
At this point, TypeScript will underline HelloComponent complaining about this:

[ts] Experimental support for decorators is a feature that is subject to change in future release. Set the 'experimentalDecorators' option to remove this warning

The "experimentalDecorators" flag is set to true in tsconfig.json, but the error is still showing up. Any idea on how to fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.