After updating to Webpack 5, I'm getting this error:
Should not import the named export 'version' (imported as 'version') from default-exporting module (only default export is available soon)
Super-simple code example:
import { version } from '../package.json';
export const appVersion = version;
This question gives a solution of import * as packageInfo from '../../package.json'; version: packageInfo.version,, but this imports all of package.json, which, as some of the comments on the answer note, could be considered a security risk.
All I need is the version number; if I have to import the entire package.json and potentially expose that to my users, it would be better to introduce code duplication and just create and maintain two separate variables:
- the version in
package.json - the version in my js app
However, I am guessing there is a secure way to import package.json without getting Webpack 5 to complain and I just don't know about it. Is there such a way?