question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does this conflict with Angular 2?

See original GitHub issue

Hi, i’m trying to use this in an Angular 2 project, but it seems that everything stops working as soon as i create an annotated object. I’m not a great Angular 2 expert so maybe it’s my fault.

I try to provide an example, starting from the Angular 2 “Quickstart”, available here https://github.com/angular/quickstart.git.

I followed these steps:

  • Installed json-typescript-mapper: npm install json-typescript-mapper --save
  • Edited systemjs.config.js, in this way:
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',

      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

      // other libraries
      'rxjs': 'npm:rxjs',
      'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',

      // Edited for: json-typescript-mapper
      'json-typescript-mapper': 'npm:json-typescript-mapper',
      'reflect-metadata': 'npm:reflect-metadata',
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular2-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      },
      // Edited for json-typescript-mapper
      'json-typescript-mapper': {
        main: './index.js',
        defaultExtension: 'js'
      },
      'reflect-metadata': {
        main: './Reflect.js',
        defaultExtension: 'js'
      }

    }
  })
  ;
})(this);
  • Create typescript class MyClass, in this way:
import {JsonProperty} from "json-typescript-mapper";

export class MyClass {
  @JsonProperty('my-prop')
  public prop: string;
}
  • Created a MyClass Object in app.module.ts:
import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent }  from './app.component';
import {MyClass} from "./my-class";

// this causes: (index):18 Error: Error: Unexpected value 'AppComponent' declared by the module 'AppModule'(…)
var data = new MyClass();

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ AppComponent ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }
  • Started the project with npm start
  • As said in the comment, this gives the error: (index):18 Error: Error: Unexpected value 'AppComponent' declared by the module 'AppModule'(…) in the browser.

Is there something i can do to use this package in an Angular 2 project?

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
djsirokycommented, Oct 10, 2016

I was able to resolve this issue with angular-cli by addingimport 'reflect-metadata'; to ./src/polyfills.ts.

This person in https://github.com/angular/angular/issues/12010 resolved it by adding that line to every component with a custom decorator, but this did the same thing for my cli project.

4reactions
jonguntercommented, Jun 21, 2017

Adding import 'reflect-metadata'; to polyfills.ts in an Angular CLI project solved my problem. I think this should possibly be added to the README instructions as it seems to be a widespread problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2 directive name conflict -- why did this not break?
1 Answer 1 ... Angular looks first to see if the name is a property of a known directive. Technically, angular is matching...
Read more >
Directive Conflict When Classes Export The ... - Ben Nadel
Ben Nadel demonstrates the directive conflict that occurs when two directives with the same class name are applied to the same view in ......
Read more >
Upgrade Angular 12 to 13 failing with peer dependency conflict
Yes Description I am trying to upgrade an Angular 12 project to version 13. ... Fix the upstream dependency conflict, or retry npm...
Read more >
AngularJS vs. Angular 2 Vs. Angular 4: Key Differences
Angular's operation employs a hierarchy of components, while AngularJS has directives that allow code reusability. So, The AngularJS framework ...
Read more >
AngularJS to Angular concepts: Quick reference
Angular does not have a bootstrap directive. To launch the application in code, explicitly bootstrap the root module ( AppModule ) of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found