'How to import a single property named with dot notation from package.json?

SonarQube detects the following code as a mistake ("Wildcard imports should not be used") :

import * as packageJson from '../../../package.json';

We use only a few of properties contained in package.json

For instance, no problem for the version, I can use that :

import { version } from '../../../package.json';

In our package.json , I want to use a property named with dot notation :

...
"project.id": "123456",
...

But the following import gives me a compilation error :

import {['project.id'] as projectId } from '../../../package.json';
error TS1141: String literal expected.

How to get correctly this single project.id property from package.json ? I don't want to rename it.



Solution 1:[1]

One solution you can change project in your package.json as below

"project":  {
   "id": "123456"
 }

and import like

import { project } from '../../project.json';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gautam Pandey