4

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

3limin4t0r
  • 19,353
  • 2
  • 31
  • 52
  • Based on `file:///index.0b...js`, I would imagine your Parcel configuration is set in a way that expects all of the built files to be served from a server root. In other words, your app could probably work if that directory was served by an HTTP server at `/`. – AKX Dec 29 '21 at 14:00
  • I tried pushing the dist folder onto GitHub Pages, but it didn't work that way. – Avinashghosh Dec 29 '21 at 16:48
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jan 06 '22 at 10:34

1 Answers1

2

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

F.I. from your terminal:

cd dist
npx serve
jsan
  • 2,794
  • 2
  • 18
  • 25
  • It works that way, but I was looking for a solution that I can open it like a normal html page. Is there any way I can do so? I'm looking into it so that I can deploy it on GitHub Pages – Avinashghosh Dec 29 '21 at 16:47
  • Github pages are served from a web server, it should be fine as long as your js are served at /index.xxx.js – jsan Dec 29 '21 at 21:17
  • If your files are not served from / try something like --public-url ./ or --public-url /your-app-url/ – jsan Dec 29 '21 at 21:20