Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS and CSS files not found after parcel build #470

Closed
haquezameer opened this issue Jan 2, 2018 · 17 comments
Closed

JS and CSS files not found after parcel build #470

haquezameer opened this issue Jan 2, 2018 · 17 comments

Comments

@haquezameer
Copy link

馃悰 bug report

parcel build index.html generates the dist folder with all the files, but launching index.html from inside the dist results in can not find css and the js files.

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

.babelrc:-

{
  "presets": [
        "env",
        "react"
    ]
}

package.json

{
"name": "referraly-frontend",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "parcel index.html"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "material-ui": "^0.20.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-router-dom": "^4.2.2",
    "typeface-roboto": "0.0.45"
  },
  "devDependencies": {
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "parcel-bundler": "^1.3.1"
  }
}

cli command : parcel build index.html

馃 Expected Behavior

Produces the build folder with the correct bundles instead of reporting missing css and js files in the browser console.

馃槸 Current Behavior

Errors in browser console on launching index.html from the build folder dist.
js_not_found

馃拋 Possible Solution

change src in script and link tags to remove errors.
eg:- change src="/dist/cfb47e75612b85db2daa42a5bbad3b67.js" to
src="./cfb47e75612b85db2daa42a5bbad3b67.js"

But still, only half of the page is displayed
half_page

馃敠 Context

Trying to produce the production build for a test deployment.

馃實 Your Environment

Software Version(s)
Parcel ^1.3.1
Node v8.6.0
npm/Yarn 5.5.1
Operating System Ubuntu 16.04
@DeMoorJasper
Copy link
Member

Change "start": "parcel index.html"
to "start": "parcel index.html --public-url /"

@haquezameer
Copy link
Author

@DeMoorJasper still does not solves the issue.
npm run start now gives a 404 error and parcel build index.html still results in css and js file not found.
Please reopen the issue if you think its a bug. Also, please comment if any additional info is required. 馃憤

@DeMoorJasper
Copy link
Member

DeMoorJasper commented Jan 2, 2018

ow my bad, i misread the start command.
U should add a build command like: parcel build index.html --public-url /
And change the start command back to what u originally had...

@haquezameer
Copy link
Author

parcel build index.html --public-url / results in the same errors on launching index.html.

@DeMoorJasper
Copy link
Member

DeMoorJasper commented Jan 2, 2018

Sorry i forgot a dot try parcel build index.html --public-url ./
this is also documented on the doc site: https://parceljs.org/production.html

@haquezameer
Copy link
Author

Ok @DeMoorJasper that solves the wrong src, sorry might have skipped that part when going through docs 馃槄 However, getting the following errors now:
consolerrorbild

I think that is not a parcel issue? Since, I am using react-router and history does not work with file:// url's maybe thats why I am getting those errors?

@DeMoorJasper
Copy link
Member

This is a react-router issue, just has to do with filesystem not being a valid url, it should work fine if u test it on an apache,nginx,.. server

@haquezameer
Copy link
Author

@DeMoorJasper Thanks for helping 馃槃

@grrunnz
Copy link

grrunnz commented Jan 24, 2018

But the default for --public-url should be ./ instead of ./dist/ since the index.html is in the dist folder.

@IsaacHub
Copy link

IsaacHub commented Apr 4, 2019

Sorry i forgot a dot try parcel build index.html --public-url ./
this is also documented on the doc site: https://parceljs.org/production.html

Now it's right here https://parceljs.org/cli.html#set-the-public-url-to-serve-on

@avalanche1
Copy link

Sorry i forgot a dot try parcel build index.html --public-url ./
this is also documented on the doc site: https://parceljs.org/production.html

@DeMoorJasper, I'm sorry, but I don't see that in the docs. So I had to google this issues :(

@Nagasai20
Copy link

Can i know what is the solution for this ? why it was closed ?

@TheOddler
Copy link

Can i know what is the solution for this ? why it was closed ?

For me the sollution seemed to be to add --public-url ./ to my parcel commands. So: parcel src/index.js --target electron --public-url ./

@DRocksCoding
Copy link

Can i know what is the solution for this ? why it was closed ?

For me the sollution seemed to be to add --public-url ./ to my parcel commands. So: parcel src/index.js --target electron --public-url ./

This worked for me too.
I was getting 404 files not found when dropping the dist folder content on my website server.
I changed my build commands like you said:
"scripts": { "dev": "parcel src/index.html", "build": "parcel build src/index.html --public-url ./" }

@SzymonRojek
Copy link

SzymonRojek commented Mar 30, 2021

I couldn't properly deploy a project (parcel bundler) on gh-pages. For me it was completely new subject, but finally I have found this post and now the code works just fine, thanks!

 "scripts": {
    "dev": "parcel index.html",
    "build": "parcel build index.html --public-url ./",
    "deploy": "rm -rf dist/ && npm run build && gh-pages -d dist"
  },

@Berkmann18
Copy link

Sorry i forgot a dot try parcel build index.html --public-url ./
this is also documented on the doc site: https://parceljs.org/production.html

Now it's right here https://parceljs.org/cli.html#set-the-public-url-to-serve-on

Both pages lead to 404s and none of the solutions here work for me.

@Sambuxc
Copy link

Sambuxc commented Nov 20, 2023

Sorry i forgot a dot try parcel build index.html --public-url ./ this is also documented on the doc site: https://parceljs.org/production.html

This link should now be -> https://parceljs.org/features/production/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests