My project contains a JSON file located at src/assets/version.json
with the following content:
{"VERSION":"1.0.0"}
I have imported this file into a TypeScript file (e.g., *.ts) as shown below:
import * as VersionInfo from 'src/assets/version.json';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor() {
console.log(`version ${VersionInfo['VERSION']}`);
}
}
The output of this code is:
version 1.0.0
This approach works flawlessly in Angular 11, but upon upgrading to Angular 12, I encountered an error as follows:
Should not import the named export 'VERSION' (imported as 'VersionInfo') from default-exporting module (only default export is available soon)
Here is a snippet of my tsconfig.base.json configuration:
{
"compileOnSave": false,
...
// Other configurations omitted for brevity
}
How can I resolve this error?