Thursday, October 26, 2017

reflect-metadata shim is required when using class decorators

This error was calling out...

C:\Users\tom.jaeschke\Documents\whatever\client\node_
      modules\@angular\core\bundles\core.umd.js:384

 
 

...where it thought reflect-metadata as an object had a {} shape, in Googling against this problem. I found threads online that suggested that...

import 'zone.js';
import 'reflect-metadata';

 
 

...should go in the polyfills.ts file at the very top to beat this problem and that obviously reflect-metadata needs to be installed too. I put...

"reflect-metadata": "0.1.10",

 
 

...inside dependencies inside of package.json naturally. Also...

import './polyfills.browser.ts';

 
 

...in my main gateway-to-the-app main.ts file. And yet, on the other side of all this I still got the error. Alright well perhaps this setup which tries to run Jasmine is good for running unit tests but not tests against components. After all, how would it even know about main.ts to find the imports we add above? Today a coworker suggested using Karma instead as the test runner and we got as far as adding this to the package.json scripts:

"test": "karma start karma.conf.js",

 
 

These commands actually get the karma runner running:

install karma
install karma-requirejs
install requirejs
karma start karma.conf.js
karma run

 
 

Obviously, the installs only have to be run once. Part of the install sets up karma.conf.js which is full of configuration and you should doctor it up after the fact. The install process lets you prefly the configuration a bit. I still don't have things working. I am probably closer. More soon.

 
 

Addendum 10/27/2017: A better list of commands is:

npm install karma
npm install karma-requirejs
npm install requirejs
karma init
npm install jasmine-core
karma start karma.conf.js
karma run

No comments:

Post a Comment