-1

I have a component library that I've created in Typescript and Angular 2. This library is consumed by my web applications via npm. The component library itself builds using both JIT and AOT compilation, but the web application which consumes it will only build successfully using JIT compilation and errors using AOT compilation.

Previously, I had an error which said MyComponentsModule is not an NgModule or something to that effect. This was solved by generating the .metadata.json files using the Angular compiler (ngc) and including them in my node module.

The error I'm currently getting is
ERROR in Unexpected token t in JSON at position 556, resolving symbol AppModule in C:/Projects/MyWebApplication/src/app/app.module.ts, resolving symbol AppModule in C:/Projects/MyWebApplication/src/app/app.module.ts.
This error itself doesn't actually tell me which JSON file that the problem is in. However, there is another message reported further up in the build process (which I can only assume is related), which states
Failed to read JSON file C:/Projects/MyWebApplication/node_modules/mycustompackage/definitions/components/address-search/address-component.metadata.json.

The address component is one of the components I have created, and the file specified is the metadata that was generated for it by ngc.

Any suggestions or avenues of investigation would be much appreciated.

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49

1 Answers1

0

After some investigation, I found that the metadata.json files generated for components that have a template were invalid. More specifically, ngc inlined the template html inside of the metadata.json as a property, but there were a few issues:

  • the template property was not wrapped in quotes e.g: "template"
  • the value of the template property was wrapped in single quotes rather than double quotes

To fix my issue and allow my web application to consume the Angular module from my node module, I simply only copied the metadata.json file for the Angular module into my package and left out all other metadata.json files.

This may not be the 'correct' fix, but it worked and I haven't found any issues with the application so far.