0

Unable to figure the error in the below React component code. Scrachted my head for a lot of time, can anyone help me out here, am I missing something?

Module build failed: SyntaxError: C:/dev/todotasks/components/Pitch.js: Unexpected character '�' (1:0) 1 | ��i m p o r t R e a c t , { C o m p o n e n t } f r o m ' r e a c t ' ;

Error from Editor

In Google Chrome

Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400
krishna
  • 575
  • 2
  • 8
  • 22
  • 1
    Have you checked if the file contains byte order mark? – Konstantin Aug 27 '16 at 06:57
  • @Alik quite sure that there are no extra characters in the Pitch.js file – krishna Aug 27 '16 at 07:18
  • Are you sure? The transpiler complains for a reason. Have you opened `Pitch.js` in a hex editor? Try to transpile the file directly in cli. – Konstantin Aug 27 '16 at 08:27
  • I have seen this error before. Delete the characters before the import statement. Watch out for the character position of import. These characters are not visible in the editor but are just unicode characters. – vijayst Aug 27 '16 at 15:13

1 Answers1

0

The file had extra characters which aren't visible in normal editors, as mentioned by @Alik and @Vijayst

So, I tried to drill more into it on how one file didn't have extra characters but other file had extra hidden characters. I narrowed it down to PowerShell commands for creation of new files.

Editor: Visual Studio Code

Terminal: PowerShell

Commands used for new file creation: "New-Item" and "Out-File"

"New-Item": This command creates new empty file. "Out-Fife": This command creates new empty file with hidden characters.

I created one of the file by using "Out-File" command which added extra characters in the beginning.

-----DO NOT use "Out-File" command in Visual Studio Code terminal for creating new files.-----

krishna
  • 575
  • 2
  • 8
  • 22
  • Powershell Out-File enforces BOM (byte order mark). http://stackoverflow.com/questions/5596982/using-powershell-to-write-a-file-in-utf-8-without-the-bom – Konstantin Aug 28 '16 at 14:24