skip to Main Content

enter image description here

I am currently working on a React web app using Parcel as the bundler. While developing, I have not encountered any issues, and the application runs smoothly with npm start. However, when I attempt to build the project using npm run build, I encounter an error that states "’const’ declarations must be initialized." The error message is as follows:

plaintextCopy code
@parcel/optimizer-swc: 'const' declarations must be initialized 
19227 
| > 19228 
| > 
| ^ 19229 
| const $e73bf42412feb220$var$Grocery = /*#__PURE__*/ (0, $acw62.lazy)(()=>(parcelRequire( 19230 |

Issue: The error seems to be related to a const declaration that lacks initialization during the build process. Strangely, the application works perfectly when running locally with npm start.

Attempts to Resolve: I have tried several methods to resolve the issue, including:

  1. Ensuring all const declarations have proper initializations.

  2. Verifying that the code runs without errors using npm start.

  3. Checking for any specific dependencies or configurations related to the build process.

  4. Reviewing the Parcel documentation and community forums for similar issues.

Request for Help: Despite these efforts, I have been unable to pinpoint the root cause of the error during the build process. If anyone has encountered a similar problem or has insights into resolving this specific issue with Parcel, I would greatly appreciate your assistance.

2

Answers


  1. I’ve got a similar error after installing the sharp package. I’m using parcel to build a react app:

    @parcel/optimizer-swc: 'const' declarations must be initialized
    
      /home/admin/framimg/node_modules/sharp/lib/libvips.js:42:0
        41 | 
      > 42 | const runtimePlatformArch = () => `${process.platform}${run
      >    | ^
        43 | 
        44 | /* istanbul ignore next */
    

    I don’t see any problem with the line causing the error…

    Login or Signup to reply.
  2. I had the same issue with Parcel 2 and Vue 3.

    I had in the main js file:

    import { createApp } from 'vue';
    import { createRouter, createWebHashHistory } from 'vue-router'
    import VueResource from 'vue-resource';
    
    import { Quasar } from 'quasar';
    
    import app from './application/app';
    import appRoutes from './application/app-routes';
    
    const app = createApp(app);
    
    app.use(createRouter({
        history: createWebHashHistory(),
        routes: appRoutes
    }));
    
    app.use(VueResource);
    
    app.use(Quasar);
    
    app.mount('#app');
    
    export default app;
    

    After change to this:

    import { createApp } from 'vue';
    import { createRouter, createWebHashHistory } from 'vue-router'
    import VueResource from 'vue-resource';
    
    import { Quasar } from 'quasar';
    
    import app from './application/app';
    import appRoutes from './application/app-routes';
    
    export default createApp(app)
        .use(createRouter({
            history: createWebHashHistory(),
            routes: appRoutes
        }))
        .use(VueResource)
        .use(Quasar)
        .mount('#app');
    

    Error has gone.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search