angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Angular 2 CLI ng build inline.js,styles.bundle.js and main.bundle.js 404 error

Open prasadrajacse opened this issue 10 years ago • 19 comments

Please provide us with the following information:

OS?

Mac OSX (El Capitan)

Versions.

angular-cli: 1.0.0-beta.17 node: 4.6.1 os: darwin x64

Repro steps.

Created a sample application using angular-cli. Ran ng build command to build the app for development.Tried to access index.html under dist folder from the browser.The following errors are seen in console

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:63342/inline.js

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:63342/inline.js

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:63342/styles.bundle.js

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:63342/main.bundle.js

index.html and above files are under same root.

Please let me know if I am going wrong.

Thanks and Regards, Durga Prasad Telu.

prasadrajacse avatar Oct 21 '16 02:10 prasadrajacse

@prasadrajacse You need to paste all the files present in the dist folder directly under the webapps folder where you must have pasted the dist folder currently.

Try this, it will work. :)

manish7singh avatar Oct 21 '16 08:10 manish7singh

I am having some custom css files referred in index.html file and after build there are missing in the dist folder.

prasadrajacse avatar Oct 21 '16 08:10 prasadrajacse

There is style.css (master css file) which applies to the whole project. You can add your custom styles to that file. Alternatively, you can try placing your custom css file to the assets folder and refer the same in your index.html. After build the assets folder is present in the dist folder. Then the file wont be missing anymore and you won't get the 404 error.

manish7singh avatar Oct 21 '16 08:10 manish7singh

index.html is managed by the CLI build system, which means that you shouldn't try to add script or css tags there directly. Instead, you can use the global styles file as shown in https://github.com/angular/angular-cli#global-styles.

Also, when you are trying to debug your app I recommend you use ng serve to serve it. Once you have verified it works with ng serve, you can try to deploy it somewhere else.

If you are deploying to a subfolder within a server, you might need to change the base tag via https://github.com/angular/angular-cli#base-tag-handling-in-indexhtml to match your subfolder path.

filipesilva avatar Oct 24 '16 20:10 filipesilva

I am running my app in linux server.I understand, I just have to copy all dist folder files into my project path in the server

  • When I did that, it worked fine for couple of hours. but now am getting the above mentioned error. 404 error.
    please correct me If I am wrong.

iamsarav avatar Apr 12 '17 12:04 iamsarav

@iamsarav I am getting the same error please let me know if you have found the solution

Ashishgollamudy avatar May 02 '17 19:05 Ashishgollamudy

I had the same problem,but I fixed it. If you are using a maven project, you must remeber all static files must be in webapp/resources. I have my index.html in webapp/ so my base path in index.html is => <base href="./resources/"> to change this path for next builds you must execute ng build --base-href /newpath/ I hope it helps you.

ghost avatar May 05 '17 03:05 ghost

@JesusMuller could you have a look on it https://stackoverflow.com/questions/44470995/angular-2-cli-how-to-use-dist-folder-files-created-by-angular-cli-ng-build

k11k2 avatar Jun 10 '17 08:06 k11k2

I just replaced the base in index.html with this now it works

pbuhrmann avatar Jun 14 '17 01:06 pbuhrmann

@JesusMuller Thanks, that does helpful.

freemansj avatar Oct 02 '17 14:10 freemansj

Okay Recently I fetched this problem I have very simple solution for solve this Issue , follow these steps: go to these directories src-> app-> index.html open the index.html and find <base href="your app name "> change this to <base href="/">

Sachin124 avatar Nov 03 '17 06:11 Sachin124

i just replace my base tag in index.html like below <base href="/">

manojrana94 avatar Dec 20 '17 06:12 manojrana94

@Sachin124 thanks man, it worked.

waqasraza123 avatar Dec 23 '17 16:12 waqasraza123

@Sachin124 thank you! I had been fighting this for 4 hours! Your suggestion fixed it for me.

isatterfield avatar Jan 07 '18 18:01 isatterfield

In my case, I had to comment out <base href="/"> to fix the 404 error.

Note*: I'm using Angular CLI version 1.6.5

bilal-korir avatar Jan 22 '18 17:01 bilal-korir

Follow steps:

  1. run ng build (keeping in mins the base url / no sub folder with command ng build)
  2. If your porject is in sub folder then then past

Use this .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    # Rewrite everything else to index.html
    # to allow html5 state links
    RewriteRule ^ index.html [L]
</IfModule>

ziaongit avatar Jan 23 '18 08:01 ziaongit

I just go to .angular-cli.json an change "deployUrl": "/" by "deployUrl": "./"

and works perfectly

yarlenvas avatar Jan 03 '19 15:01 yarlenvas

@yarlenvas Just a quick note that a deploy URL of ./ is the equivalent of not having a deploy URL defined.

clydin avatar Jan 03 '19 15:01 clydin

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.