Angular build index.html not working
Asked Answered
H

3

9

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?

Henleyonthames answered 7/3, 2018 at 9:54 Comment(1)
You have to open the page using localhost:4200, it is said when you run ng start.Boden
A
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

Atingle answered 7/3, 2018 at 9:57 Comment(4)
It is working Thanks.Why it is still working if i remove the base element?Henleyonthames
Yes it is woking if the element not thereHenleyonthames
I'm not sure Sir, I don't know what is the default base url once you remove this tagAtingle
This didn't work for me. I got nothing when I add <base href="./">. When I removed base tag, I got an error. Please provide a value for the APP_BASE_HREF token or add a base element to the document.Bikini
M
3

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

Maladroit answered 14/5, 2020 at 6:9 Comment(0)
T
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.

Tibbs answered 4/10, 2020 at 6:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.