UPDATE: the issue is fixed by this PR
Be ware of that the reason that the problem comes out and normal pure JavaScript ways cannot solve it could be because that server.ts is using TypeScript and Webpack. Check Gant's answer. And track this issue on github.
I am using angular/universal-starter as starter. I have a file config.json
{
"api": "123"
}
When I read config in server.ts:
import * as config from '../config.json';
// const config = require('../config.json'); will be same result
console.log(config);
It shows this in the terminal:
{
"api": "123"
}
However, when I try to read config.api in server.ts:
import * as config from '../config.json';
// const config = require('../config.json'); will be same result
console.log(config.api);
It shows undefined.
This is my folder structure (other part same like angular/universal-starter).
my-app
- config.json
+ src
- server.ts
And when I launch the app, I use npm start.
What may cause this? Thanks
import config from './config.json';. If its in node, you can just require it. const config = require('./config.json').console.log(config);andconsole.log(config.api);will showundefinedconfig.jsonin that repository.config.jsonis my own file.