Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read property 'toString' of undefined Angular 6

Tags:

angular

I'm trying to build a library with angular 6 but I'm facing some problems.

Before adding --SoumissionStructComponent-- to my library module nothing wrong happens

But once I add it i got this one

TypeError: Cannot read property 'toString' of undefined
 at new Input (C:\Users\taha.manar\Documents\workspace\Adjucation-Ihm\node_modules\ng-packagr\node_modules\postcss\lib\input.js:53:20)
 at parse (C:\Users\taha.manar\Documents\workspace\Adjucation-Ihm\node_modules\ng-packagr\node_modules\postcss\lib\parse.js:13:15)
 at new LazyResult (C:\Users\taha.manar\Documents\workspace\Adjucation-Ihm\node_modules\ng-packagr\node_modules\postcss\lib\lazy-result.js:60:16)
 at Processor.<anonymous> (C:\Users\taha.manar\Documents\workspace\Adjucation-Ihm\node_modules\ng-packagr\node_modules\postcss\lib\processor.js:138:12)
...

SoumissionStructComponent.ts

import { Component, OnInit } from '@angular/core';
import { SoumissionService } from './soumission.service';
import { ListElements, ElementList } from './../Common/root-page/model/ElementList';

@Component({
  selector: 'app-soumission-struct',
  templateUrl: './soumission-struct.component.html',
  styleUrls: ['./soumission-struct.component.css']
})
export class SoumissionStructComponent implements OnInit {
  listElements: ListElements;
  elementsList: ElementList[] = [];
  constructor(private soumissionService: SoumissionService) {
soumissionService.getActivatedSoumission().subscribe((r: any) => {

  this.listElements = new ListElements();
  this.listElements.listElts = [];
  if (r) {
    this.listElements.listElts.push({ key: r.id, value: r.seanceDate });
  }
});
  }

  ngOnInit() {
  }

}

Hope i've described the problem clearly

like image 770
taha manar Avatar asked Oct 31 '18 15:10

taha manar


2 Answers

Did you change your css -> scss after ng generate? If so then you need to update styleUrls.

like image 75
Anthony Avatar answered Sep 30 '22 01:09

Anthony


Pretty much the same as Anthony's answer, but for me, I get this because I prefer inline templates and styles but I forget to include -s -t flags when using ng generate (especially in lib projects where the global inline settings in angular.json don't seem to stick?).

After I do an ng generate I delete the foo.html and foo.scss files to avoid going into a trance while alt-tabbing 20 times in 5 seconds.

Then, I change templateUrl to template:

foo works

(note: replace the single quotes from the url string with the template's tickmarks).

I then often forget to change the styleUrl['foo.scss'] to styles:[``] and then this error message pops up. This is quite a lame error message from a great tool but I thinks it has something to do with the opacity of webpack.

like image 42
Michael Bushe Avatar answered Sep 30 '22 00:09

Michael Bushe