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:
-
Ensuring all
const
declarations have proper initializations. -
Verifying that the code runs without errors using
npm start
. -
Checking for any specific dependencies or configurations related to the build process.
-
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
I’ve got a similar error after installing the
sharp
package. I’m using parcel to build a react app:I don’t see any problem with the line causing the error…
I had the same issue with Parcel 2 and Vue 3.
I had in the main js file:
After change to this:
Error has gone.