I'm trying to import a local file to use the data in it. I have tried the require method and the import method. Neither seems to work. I'm using Angular 5 and Typescript 2.9.2. I am locked to angular 5. I'm building for aot and when I look at the fesm5 file that gets exported the json file does not seem to resolve. (I DO NOT WANT TO PULL IT IN WITH HTTP...)
import * as data from '../../assets/file.json';
When I try to set tsconfig value to:
"resolveJsonModule": true,
I get an error on build:
Cannot read property 'slice' of undefined
TypeError: Cannot read property 'slice' of undefined
at addReferencesToSourceFile (/Users/ME/Projects/PROJECT/node_modules/@angular/compiler-cli/src/transformers/compiler_host.js:520:54)
at TsCompilerAotCompilerTypeCheckHostAdapter.getSourceFile (/Users/ME/Projects/PROJECT/node_modules/@angular/compiler-cli/src/transformers/compiler_host.js:348:13)
I have also tried the:
declare module '*.json' {
const value: any;
export default value;
}
This doesn't seem to help at all.
Also tried:
declare function require(url: string);
var data = require('../../assets/file.json');
This does not seem to resolve the json in the final file either.