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

Generated files are not UTF-8 encoded

Open HugCoder opened this issue 10 years ago • 14 comments

Please provide us with the following information:

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) Win10

  2. Versions. Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here: angular-cli: 1.0.0-beta.11-webpack.8 node: 6.5.0 os: win32 x64

  3. Repro steps. Was this an app that wasn't created using the CLI? What change did you do on your code? etc. Generate a component or a new project. The files do not support UTF-8 chars, like åäö (Swedish). When rendered in HTML they appear as symbols. Changing the file encoding to UTF-8 (with or without BOM) fixes this.

  4. The log given by the failure. Normally this include a stack trace and some more information. N/A

  5. Mention any other details that might be useful. See step 3.


    Thanks! We'll be in touch soon.

HugCoder avatar Sep 13 '16 01:09 HugCoder

I did some more tests now and it turns out that even if I manually change the encoding on the .ts and .html files, it seems like it reverts back to ANSI encoding again when webpack compiles it all, at least the .ts files. Searching on this issue made me find this: "webpack-encoding-plugin" (https://github.com/quackes/webpack-encoding-plugin) and the issue seems like it might be related to this: https://github.com/webpack/webpack-dev-server/issues/432

The problem with angular-cli though is that it seems like there are no webpack.config files to add our own plugins or settings to. Maybe there's a way through angular-cli.json and adding it in "addons" or "packages"? So currently I cannot test if the plugin solves this issue. It would probably be good to add it natively to angular-cli though, since utf-8 encoding should be the base for everything in a modern web project.

HugCoder avatar Sep 13 '16 20:09 HugCoder

I tried to repro and got UTF-8 encoded files througout. image

Also on Win10, using VSCode myself. It is maybe your editor?

filipesilva avatar Sep 21 '16 03:09 filipesilva

Thanks for answering!

Hmm, Yes, Visual Studio 2015 seems to re-save everything in ANSI. I found a "solution" by installing the "ForceUTF8" VS Extension: https://visualstudiogallery.msdn.microsoft.com/222add7a-54a6-4fdd-b6f1-5d95cc596b42 but it doesn't exactly feel like a good/solid solution since if this would suddenly stop working/get disabled, things get worse. This is because I also noticed while manually changing the encoding, and VS re-saving to ANSI, I got weird symbols in the editor as well, which could be a pain to keep restoring to the original chars. I guess it's VS to blame though, no idea why they cannot simply default to UTF-8 for everyone instead of ANSI. I guess I could develop the Angular part of the project in VS Code, while using VS2015 for the server code only. VS Code seems more compatible with the Angular CLI style of taking in new generated files automatically anyway. VS2015 requires you to add them to the project manually all the time.

HugCoder avatar Sep 21 '16 12:09 HugCoder

Sorry I can't help you more than this, I don't think there's much we can do on the CLI side :/

filipesilva avatar Oct 03 '16 13:10 filipesilva

I have the same problem in CLI when I transfer Dist files to server and use IIS all persian fonts have bad encoding , and They are not UTF8 What Can I Do ???

keivankashani avatar Oct 07 '17 14:10 keivankashani

Having the same encoding problem with ng build --prod, fonts encoding is wrong, any solution for this?

nomykk avatar Mar 05 '18 09:03 nomykk

For Spring and Spring Boot Apps, I found the solution here: https://github.com/angular/angular-cli/issues/7053

including these properties resolved the encoding issue for me.

spring.messages.encoding=UTF-8 server.tomcat.uri-encoding=UTF-8 spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true spring.http.encoding.force=true

nomykk avatar Mar 05 '18 11:03 nomykk

Your answer is for Tomcat Web Server. Do you know a solution for IIS ?

keivankashani avatar Mar 05 '18 12:03 keivankashani

I don't know any solution for IIS, sorry dear.

nomykk avatar Mar 05 '18 12:03 nomykk

No  I don't know any solution for IIS, sorry dear. — You are receiving this because you are subscribed to this thread. Reply to this email directly, zasobygwp.pl view it on GitHub , or zasobygwp.pl mute the thread .

Sadlowski avatar Mar 05 '18 12:03 Sadlowski

We have this issue here with files created with the CLI and then imported into visual studio (2015 and 2017). After saving in VS, when looking at the encoding the files claim they are utf-8, however they are in reality encoded in ISO-8859-1. The issue seems to arrise from the fact that VS expects UTF-8 with BOM, and not utf-8, then it finds that the file is not correctly encoded and saves it as ISO-8859-1.

chpoit avatar Mar 07 '18 20:03 chpoit

For Visual Studio 2017, I solved this by turning off Auto-detect UTF-8 encoding without signature and Follow project coding conventions.

Got to: Tools | Options | Text Editor | General: then uncheck Auto-detect UTF-8 encoding without signature and Follow project coding conventions.

kostia24 avatar Apr 23 '18 10:04 kostia24

Got to: Tools | Options | Text Editor | General: then uncheck Auto-detect UTF-8 encoding

This will make Visual Studio incorrectly display non-ASCII characters in files that were saved without BOM. I usually want to leave "Auto-detect UTF-8 encoding" enabled, otherwise when I open a file with non-ASCII multibyte characters in Visual Studio and save it, VS decides its ASCII and corrupts the non-ASCII multibyte characters.

So, in general this solution does not work. I don't know a clean way to force Visual Studio to automatically save non-BOM as UTF8 if you happen to be the first person to add non-ASCII characters to the file. I just tested - in such scenario, VS saves non-ASCII chars as a single byte. You have to manually resave the file picking UTF8 without BOM in VS to make it work correctly.

progmars avatar Jul 18 '19 10:07 progmars

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.