Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run production build of a ReactJS app with Parcel bundler?

I'm just trying to generate a build using parcel build /src/index.html, I'm able to build the app, but when I try to open the build form a browser, it says it is unable to access index.js from index.html after build.

<body>
    <div id="root"></div>
    <script src="index.js" type="module"></script>
</body>

Anyway, Im having no issues on running the project locally. Please take a look at the images below to understand my concern. Thanks.

Console error after opening index.html from build

Project structure

like image 221
Avinashghosh Avatar asked Oct 26 '25 10:10

Avinashghosh


2 Answers

You need to serve the dist directory from a web server.

F.I. from your terminal:

cd dist
npx serve
like image 93
jsan Avatar answered Oct 28 '25 22:10

jsan


You can add this in scripts in package.json if it is an npm project

"build": "parcel build index.html", 

This will give you an production build or simply run

npx parcel build index.html

And to run the application on local

cd dist
npx serve
like image 42
thenm Avatar answered Oct 29 '25 00:10

thenm