Angular 6 production build throwing Syntax Errors

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Angular 6 production build throwing Syntax Errors



I have a project that runs fine & also when I ran the command ng build--prod it complies successfully & I get the dist folder in my project. Now I have xammp installed on my machine so I copied that folder & pasted in the htdocs folder. So now I can access that folder as localhost/dist but the app throws the below errors & app is not running. Can any one tell me whats the problem exactly.


ng build--prod


htdocs


GET http://localhost/styles.34c57ab7888ec1573f9c.css 404 (Not Found)
GET http://localhost/main.d3384476e7e827a9f05c.js 404 (Not Found)





you can define the base url in index.html and other thing is you can provide full path in index.html eg. C/xampp/folder/dist/
– Bhavya Sanchaniya
Aug 8 at 5:24




2 Answers
2



By default baseUrl is / hence it starts looking for resources in the root folder.
You have two possible solutions.


baseUrl


/



Specify the base URL. you can specify base URL in index.html manually as
in head tag
<base href="dist/">
Or you can specify it on the time of building angular-cli has a builtin switch --base-href


index.html


head


<base href="dist/">


--base-href



E.g:
ng build --prod --base-href /dist/


ng build --prod --base-href /dist/



For more information refer to angular-cli documentation





Bingo..!! That solved my problem buddy thank you.
– Jignesh Mistry
Aug 8 at 5:47



In Angular 6, you can specify the baseHref and deployUrl in "angular.json" config.





...
"projects":
"project-name":
...
"architect":
"build":
"options":
"baseHref": "/dist/",
"deployUrl": "/dist",
...









In this way, you don't have to modify your index.html and also don't need to input extra params in command line to build your app.





In this way, dev build will also be running with "baseHref": "/dist/" is there a way to specify it in only for production configurations?
– Talha Junaid
Aug 8 at 8:49



"baseHref": "/dist/"





Isn't it a good practice to keep dev and prod environment consistent, so that you don't need to worry about something works in dev but not in prod?
– Charles Zhao
Aug 8 at 10:08






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS