Parcel: Cannot serve static assets created via "parcel build src/index.html"

Created on 9 Feb 2019  路  5Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

App works perfectly when running locally using parcel src/index.html, however after creating a production bundle by running parcel build src/index.html and attempting to serve the static assets using vscode live serve or serve the app is being served with missing CSS and JavaScript files. The same thing happens when the app is served via github pages. Interestingly enough, http-serve is able to serve the app in its entirety. The repository containing whole source code can be found here

馃帥 Configuration (.babelrc, package.json, cli command)

package.json

馃 Expected Behavior

App is being served including CSS and JavaScript files.

馃槸 Current Behavior

App is served without CSS and JavaScript assets

Errors when accessing page served by github

src.184de31a.css:1 Failed to load resource: the server responded with a status of 404 ()
src.152c138c.js:1 Failed to load resource: the server responded with a status of 404 ()
src.184de31a.css:1 Failed to load resource: the server responded with a status of 404 ()

馃拋 Possible Solution

Changing the mime types of CSS and JavaScript assets

馃捇 Code Sample

The repository containing whole source code can be found here

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.11.0
| Node | 10.7.0
| npm/Yarn | 6.5.0
| Operating System | Linux

Bug Stale

Most helpful comment

Hello @mytee306, you can set the option --public-url. To make github pages work for instance, you have two options:

parcel build src/index.html --public-url='./'.

It would then serve the assets from https://mytee306.github.io/nns/ as opposed to https://mytee306.github.io.

Alternatively

parcel build src/index.html --public-url='/nns' should work too - same logic.

Someone correct me if I'm wrong, but the reason it doesn't work is that by default parcel expects that the bundle is in the server's top-most / root directory. In github pages case, they are nested in nns/. So if you run serve / http-server in dist/ it should work. If you run them one folder above, it won't, unless you set --public-url

All 5 comments

Hello @mytee306, you can set the option --public-url. To make github pages work for instance, you have two options:

parcel build src/index.html --public-url='./'.

It would then serve the assets from https://mytee306.github.io/nns/ as opposed to https://mytee306.github.io.

Alternatively

parcel build src/index.html --public-url='/nns' should work too - same logic.

Someone correct me if I'm wrong, but the reason it doesn't work is that by default parcel expects that the bundle is in the server's top-most / root directory. In github pages case, they are nested in nns/. So if you run serve / http-server in dist/ it should work. If you run them one folder above, it won't, unless you set --public-url

@lustoykov Works like a charm, thank you so much!

Shouldn't parcel change default then? Looks like a bug.

@mihailik I was wondering the same, would be nice to hear the opinion of a contributor. As far as I can tell --public-url './' does not bring unwanted side effects.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mnn picture mnn  路  3Comments

medhatdawoud picture medhatdawoud  路  3Comments

Niggler picture Niggler  路  3Comments

will-stone picture will-stone  路  3Comments

dotdash picture dotdash  路  3Comments