Error: Should not import the named export 'version' (imported as 'version')

Muhammad Kamal picture Muhammad Kamal · Nov 24, 2020 · Viewed 33k times · Source

I have an ejected create-react-app project. I am getting this error after updating it to webpack 5. It was working fine with webpack v4.41.5

OS: MacOS Catalina 10.15.7
node: v10.23.0

Error: Should not import the named export 'version' (imported as 'version') from default-exporting module (only default export is available soon).

Answer

Splaktar picture Splaktar · Apr 22, 2021

As noted in the comments, it is not recommended to expose your package.json file like this.

Change the following

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

to something like

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

And then change your access from something like

version,

or

version: version,

to

version: packageInfo.version,