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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"index.html could not be copied to 404.html. Continuing without an error." for Angular 6 #37

Closed
DavidHulsman opened this issue May 12, 2018 · 56 comments

Comments

@DavidHulsman
Copy link

Created an empty Angular 6 application. Installed ngh globally and then ran the next two commands:

ng build --prod --base-href https://dutchmandavid.github.io/angular-io-code
ngh

then got this as output:

(node:1756) ExperimentalWarning: The fs.promises API is experimental
index.html could not be copied to 404.html. Continuing without an error.
Successfully published!

The url itself (https://dutchmandavid.github.io/angular-io-code) now gives the next error:

File not found

The site configured at this address does not contain the requested file.

Copying index.html and renaming it to 404.html does nothing - even after rebuilding and ngh-ing it again.


Archive for if the page ever changes: http://archive.is/uQxVg (web.archive.org didn't want to cooperate)

@DavidHulsman
Copy link
Author

Turns out Angular 6 changed angular.json's "outputPath": "dist/" into "outputPath": "dist/[PROJECTNAME]", which placed everything in the dist folder in a subfolder, which breaks ngh's functionality.

After turning the option from the latter into the former everything works again.

@JohannesHoppe
Copy link
Member

thanks for reporting! i will think about a solution...

@fmalcher
Copy link
Member

For now, until we provided a solution for this, you can solve this by doing:

ngh --dir dist/[PROJECTNAME]

@imancini
Copy link

imancini commented May 23, 2018

@fmalcher Could you please explain what ngh --dir dist/[PROJECTNAME] does? I tried using it, and it made my error go away, but when I visit 'https://[username].github.io/[projectname]', I am still just seeing the basic Angular CLI readme page and not my actual angular project running correctly.

@fmalcher
Copy link
Member

ngh --dir dist/[PROJECTNAME] takes the specified build directory dist/[PROJECTNAME] and publishes it to the gh-pages branch (if not specified differently).
However, when publishing to GH Pages under a subfolder you also need to set the base href accordingly at build time:

ng build --prod --base-href=/[projectname]/

Otherwise your browser will try to find the application bundles in the domain root and not in the subfolder. Note the leading and trailing slash, they are important.
There is no need to set the base href when you deploy to a domain root without sub folder.

I just tried both ways and they worked fine. Please let us know if there are issues!
@imancini

@JohannesHoppe
Copy link
Member

Please also take a look at angular.json, scroll down to "defaultProject":.
Thats the name of you project and also the name of its folder in /dist.
Most probably that the value you have to enter for [PROJECTNAME] as described by @fmalcher .

@imancini
Copy link

@fmalcher @JohannesHoppe Thank you for the clear description. This makes a lot more sense now. I ended up getting it to work last night by changing my github pages deploy branch to the gh-pages one that was created by the ngh --dir dist/[PROJECTNAME] command.

When I built, I still ran ng build --prod --base-href "http://[username].github.io/[projectname]" which I'm not sure is ideal because the base href was set to that URL which broke all of my image paths. To fix this though, I set a custom base href in my development index.html to fix them and just used a relative path to assets/image.jpg for my images and that works for both production and development.

Thank you!!

@Abelhawk
Copy link

Abelhawk commented Jul 1, 2018

"Failed to load resource: the server responded with a status of 404 ()"

@JohannesHoppe
Copy link
Member

There could be multiple reasons for that. Usually it's a configuration error. You could debug this now, or you need to wait some time until I add some upfront validations to the code. I'm sorry. Busy time for us here.

railsstudent added a commit to railsstudent/ng-fun-prog that referenced this issue Jul 2, 2018
railsstudent added a commit to railsstudent/ng-fun-prog that referenced this issue Jul 2, 2018
railsstudent added a commit to railsstudent/ng-fun-prog that referenced this issue Jul 2, 2018
@romanshutsman
Copy link

solution for me:

ng build --prod --output-path project --base-href "https://romanshutsman.github.io/project/"
ngh --dir=dist/project

but you should change path to photos

@Pandeyjidev
Copy link

Pandeyjidev commented Jul 18, 2018

I'm still getting an error .. This comes up as soon as I do

ngh --dir dist/

My project folder is in the following sequence portfolio -> dist -> portfolio -> index.html

@fmalcher any other way I can work this out?

An error occurred!
Error: Unspecified error (run without silent option for detail)
at /usr/local/lib/node_modules/angular-cli-ghpages/node_modules/gh-pages/lib/index.js:232:19
at _rejected (/usr/local/lib/node_modules/angular-cli-ghpages/node_modules/q/q.js:844:24)
at /usr/local/lib/node_modules/angular-cli-ghpages/node_modules/q/q.js:870:30
at Promise.when (/usr/local/lib/node_modules/angular-cli-ghpages/node_modules/q/q.js:1122:31)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/angular-cli-ghpages/node_modules/q/q.js:788:41)
at /usr/local/lib/node_modules/angular-cli-ghpages/node_modules/q/q.js:604:44
at runSingle (/usr/local/lib/node_modules/angular-cli-ghpages/node_modules/q/q.js:137:13)
at flush (/usr/local/lib/node_modules/angular-cli-ghpages/node_modules/q/q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)

@JitendraGurjar
Copy link

I'm getting following error
"index.html could not be copied to 404.html. Continuing without an error.
Successfully published!"
also adding screenshot.
image

Inside angular.json
image
And "defaultProject": "ngProj"

But when I am trying to hit the URL it gives me an following error.
image

Please help me to resolve this issue. Thank you

@JohannesHoppe
Copy link
Member

@JitendraGurjar This is an Angular 6 project. Path has changed from 5 to 6. For now, add the option --dir=dist/ngProj. In future I will add an automatic detection

@JitendraGurjar
Copy link

Thank you for your quick response.
I have changed to
"defaultProject": "dist/ngProj" in angular.json

But still getting the same error.

@JohannesHoppe
Copy link
Member

You are not supposed to change the anguar.json file!!
Just execute ngh --dir=dist/ngProj. Chances are high, that you have to adjust more command line arguments. Please read the README carefully and please take special care about credentials (GH_TOKEN ).

@romanshutsman
Copy link

romanshutsman commented Jul 20, 2018 via email

@listgaus
Copy link

is there any solution by now? im experiencing issues deploying my project
after typing ng build --prod --output-path PROJECT --base-href "

ng --dir=dis/project
raises an error evey time

@JohannesHoppe
Copy link
Member

The command of this project is called ngh. NOT ng.

@listgaus
Copy link

yes small error in my comment here, used ngh
but im afraid i still got the same errors as @JitendraGurjar mentioned.

@JitendraGurjar
Copy link

@JohannesHoppe thank you for your support.

image

I tried that command but still not working, earlier it was showing 404 but now it is showing a blank page.

image

@fmalcher
Copy link
Member

@JitendraGurjar You should see the error in the browser console.
Most probably the base-href option is missing, as explained here: #37 (comment)

@Serhansolo
Copy link

Serhansolo commented Jul 26, 2018

Guys, I was just trying to get things working and I noticed that setting a --base-path of ./ also works when deploying to ghpages.

the exact commands I used were:
ng build --prod --base-href="./"

and after that I did:
ngh --branch="production" --dir="dist/[name-of-your-app]"


Note by Johannes:
Don't use this advice. Code will break on hard reloads.

@romanshutsman
Copy link

romanshutsman commented Jul 26, 2018

@JitendraGurjar try write in index.html <base href="">


Note by Johannes:
Don't use this advice. Code will break on hard reloads.

@Serhansolo
Copy link

@romanshutsman I am not sure how correct it is to change the contents of your built files...

@JohannesHoppe
Copy link
Member

JohannesHoppe commented Aug 29, 2018

Have you tried:
ngh --no-silent --dir=dist/myapp1 (two dashes)

@boristep1
Copy link

It works

@djblanc360
Copy link

@JohannesHoppe when I use ngh --no-silent --dir=dist/myapp1

my error is
ProcessError: fatal: AggregateException encountered.
One or more errors occurred.
bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for 'https://github.com': Invalid argument

Also tried npx ngh --repo=https://GH_TOKEN@github.com/organisation/your-repo.git --name="Displayed Username" --email=mail@example.org
from #36

@Cygra
Copy link

Cygra commented Sep 20, 2018

My error msg is also index.html could not be copied to 404.html. Continuing without an error.

I solved this problem magically by adding /index.html on the end of the URL after struggling for more than ten minutes.

@manimayan
Copy link

Execute one by one in GIT BASH. I got rid of 404.html problem

npm i angular-cli-ghpages --save-dev
ng build --prod --base-href "https://USERNAME.github.io/REPOSITORY_NAME/"
npx ngh --no-silent

@gaizik
Copy link

gaizik commented Mar 23, 2019

I came across this issue myself the way I was able to solve it was to first change the "outputPath" in angular.json from "dist/[PROJECT NAME]" to "dist/"

then run
ng build --pord --base-href https://[USERNAME].github.io/[REPONAME]/index.html

Why/How does this work idk, all ik is it worked and you can check here: https://antpowell.github.io/DisclAImer

@gaizik
Copy link

gaizik commented Mar 23, 2019

OMFG Thank you !!!!!

@Sathishchary
Copy link

@gaizik I have followed the all the steps, But I could not deploy my project in github,its showing error when pushing ..

Followed this steps:
Changed the "outputPath": "dist/", in angular.json file.
ng build --prod --base-href "https://[userName].github.io/[ProjectName]"
npx ngh --no-silent
--->
Committing
Pushing
*** An error occurred!

{ ProcessError: bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for 'https://github.com': No error

any changes i need to do ?

@JohannesHoppe
Copy link
Member

You have to authenticate. Read that part about GH_TOKEN

@KothaSathish
Copy link

Thanks for reply @JohannesHoppe , Can you please elaborate GH_TOKEN, and Any suggestion links.

@nyembotech
Copy link

hi guys I just want to deploy my app to firebase and I have this problem

"This file does not exist and there was no index.html found in the current directory or 404.html in the root directory.

Why am I seeing this?
You may have deployed the wrong directory for your application. Check your firebase.json and make sure the public directory is pointing to a directory that contains an index.html file.

You can also add a 404.html in the root of your site to replace this page with a custom error page."

@nyembotech
Copy link

Any help

@loaizamateo
Copy link

image

Error in angular 8

@niraliG
Copy link

niraliG commented Feb 2, 2020

For now, until we provided a solution for this, you can solve this by doing:

ngh --dir dist/[PROJECTNAME]

this worked reallly great
thanks for posting

@erniephillips
Copy link

FOUND THE WORKING FIX!!!
The explanation is here: https://angular.io/guide/deployment#deploy-to-github-pages

  1. Run: ng build --prod --output-path docs --base-href /your-project/
  2. make a copy of docs/index.html and name it docs/404.html
  3. ngh --dir dist/docs
  4. open in browser, see my working example: https://erniephillips.github.io/phillips-computer-repair-shop/

Happy coding.

@JohannesHoppe
Copy link
Member

To all of you. Please read the following article first, many questions should be answered there:

https://angular.schule/blog/2020-01-everything-github

Among other things the new API (ng deploy) is shown here.

@erniephillips
Copy link

erniephillips commented Feb 16, 2020

To all of you. Please read the following article first, many questions should be answered there:

https://angular.schule/blog/2020-01-everything-github

Among other things the new API (ng deploy) is shown here.

That seems much more straight forward. It's just the one command:
ng deploy --base-href=/your-project/

Thank you!

@Atekawere
Copy link

npx angular-cli-ghpages --dir=dist/git
index.html could not be copied to 404.html. This does not look like an angular-cli project?!
(Hint: are you sure that you have setup the directory correctly?)
Diagnostic info: ENOENT: no such file or directory, stat '/home/victor/Desktop/Git-Search/Git/dist/git/index.html'
👨🚀 Uploading via git, please wait...
❌ An error occurred when trying to deploy:
ENOENT: no such file or directory, stat '/home/victor/Desktop/Git-Search/Git/dist/git'

getting this error that i dont understand

shigimcp added a commit to shigimcp/cbakerphoto that referenced this issue Apr 18, 2020
…S ***!!

- REF: https://alligator.io/angular/deploying-angular-app-github-pages/
- trying angular-cli-ghpages again
- ng build --prod --base-href "cbakerphoto"
- ng --dry-run
- ngh --message="Another deploy attempt via angular-cli-ghpages"

NO! DO-OVER!
- REF: https://medium.com/tech-insights/how-to-deploy-angular-apps-to-github-pages-gh-pages-896c4e10f9b4
- ng build --prod --base-href "https://shigimcp.github.io/cbakerphoto/"
- npx angular-cli-ghpages — dir=dist/cbakerphoto
- OOPS! npx angular-cli-ghpages — dir=dist/cbakerphoto-app/
- RESULT: 404 error at https://shigimcp.github.io/cbakerphoto/

DO OVER! AGAIN!
- REF: angular-schule/angular-cli-ghpages#37
- REF: https://angular.io/guide/deployment#deploy-to-github-pages
- ng build --prod --output-path ../docs --base-href /cbakerphoto-app/
- npx angular-cli-ghpages — dir=dist/cbakerphoto-app/

- REF: https://medium.com/tech-insights/how-to-deploy-angular-apps-to-github-pages-gh-pages-896c4e10f9b4
- ng build —base-href="https://shigimcp.github.io/cbakerphoto/"

- OH, FUGGIT! I'm just scrambling now...
szymonkobus added a commit to szymonkobus/split that referenced this issue Apr 26, 2020
szymonkobus added a commit to szymonkobus/split that referenced this issue Apr 27, 2020
@tibari1980
Copy link

Solution for me : worked successfully!!!!!!
image

ng build --prod --output-path project --base-href="https://tibari1980.github.io/SiteAngular7/"
ngh --dir=dist/FontEndPiXABAY

@tibari1980
Copy link

Second screen :
image

@deepakcs7050
Copy link

index.html could not be copied to 404.html. This does not look like an angular-cli project?!
(Hint: are you sure that you have setup the directory correctly?)
Diagnostic info: ENOENT: no such file or directory, stat '/home/deepak/deepaktest/Vishal/imortant folder/Angular_deploy_demo/dist/dist/index.html'
🚀 Uploading via git, please wait...
❌ An error occurred when trying to deploy:
ENOENT: no such file or directory, stat '/home/deepak/deepaktest/Vishal/imortant folder/Angular_deploy_demo/dist/dist'

@fmalcher
Copy link
Member

@deepakcs7050 It looks like youre trying to run the command from the dist folder. Please run it from the project root. 🙂
If this doesn't help, please post the exact command you entered.

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

No branches or pull requests