Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 595
Muhammad Kamal Avatar asked Nov 24 '20 18:11

Muhammad Kamal


3 Answers

Change the following

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

to something like

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

And then change your access from something like

version,

or

version: version,

to

version: packageInfo.version,

As noted in the comments, there may be cases where you do not want to expose your entire package.json file in the client code.

like image 129
Splaktar Avatar answered Nov 15 '22 13:11

Splaktar


You should also add "allowSyntheticDefaultImports": true, to the compileroptions in the tsconfig.json

like image 30
Edwin Witlox Avatar answered Nov 15 '22 14:11

Edwin Witlox


I solved my issue with the following:

    import packageInfo from './package.json';
    
    
    version = packageInfo.version;
like image 26
Hadi Masoumi Avatar answered Nov 15 '22 12:11

Hadi Masoumi