8

I have taken the build of angular project and got dist folder.when i am trying to open the index.html in browser.I am getting the following error like failed to load resources and file not found for inline.bundle.js ,polyfil.bundle.js and many files. enter image description here Though this files added in the script tag and i didnt change the path of this file still not working.But if i run this from live server it is working. enter image description here Explain why it is not working without server? Why it is not loading the inline.bundle.js,polyfill.bundle.js which are js file?

David Walschots
  • 12,279
  • 5
  • 36
  • 59
John Willson
  • 444
  • 1
  • 3
  • 13
  • You have to open the page using `localhost:4200`, it is said when you run `ng start`. – Akxe Jan 11 '19 at 13:08

3 Answers3

13

Your files are not found because base URL changed.

You can workaround this one by using <base href="./"> in your index.html.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

Zooly
  • 4,736
  • 4
  • 34
  • 54
3

You can also use the ng build --base-href ./ command, so that modifying the HTML file is not necessary.

WSD
  • 3,243
  • 26
  • 38
0

According to Mozilla:

The HTML <base> element specifies the base URL to use for 
all relative URLs in a document. There can be only one <base> element in a document.

This means all the compiled resources are being referenced in relation to the root of the system. for instance the style and the images are in the same folder as the index.html. making the base url <base href="/"> or <base href="foldername of the index.html">makes it to reference to the current folder.

Tadele Ayelegn
  • 4,126
  • 1
  • 35
  • 30