webpackwebpack-5

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


Solution

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