No visible cause for “Unexpected token ILLEGAL”

后端 未结 11 2254
轻奢々
轻奢々 2020-11-22 00:09

I\'m getting this JavaScript error on my console:

Uncaught SyntaxError: Unexpected token ILLEGAL

This is my code:

相关标签:
11条回答
  • 2020-11-22 01:02

    I had the same problem on my mac and found it was because the Mac was replacing the standard quotes with curly quotes which are illegal javascript characters.

    To fix this I had to change the settings on my mac System Preferences=>Keyboard=>Text(tab) uncheck use smart quotes and dashes (default was checked).

    0 讨论(0)
  • 2020-11-22 01:02

    If you are running a nginx + uwsgi setup vagrant then the main problem is the Virtual box bug with send file as mentioned in some of the answers. However to resolve it you have to disable sendfile in both nginx and uwsgi.

    1. In nginx.conf sendfile off

    2. uwsgi application / config --disable-sendfile

    0 讨论(0)
  • 2020-11-22 01:04

    This also could be happening if you're copying code from another document (like a PDF) into your console and trying to run it.

    I was trying to run some example code out of a Javascript book I'm reading and was surprised it didn't run in the console.

    Apparently, copying from the PDF introduces some unexpected, illegal, and invisible characters into the code.

    0 讨论(0)
  • 2020-11-22 01:05

    I had this same problem and it occurred because I had hit the enter key when adding code in a text string.

    Because it was a long string of text I wanted to see it all without having to scroll in my text editor, however hitting enter added an invisible character to the string which was illegal. I was using Sublime Text as my editor.

    0 讨论(0)
  • 2020-11-22 01:06

    why you looking for this problem into your code? Even, if it's copypasted.

    If you can see, what exactly happening after save file in synced folder - you will see something like ***** at the end of file. It's not related to your code at all.

    Solution.

    If you are using nginx in vagrant box - add to server config:

    sendfile off;
    

    If you are using apache in vagrant box - add to server config:

    EnableSendfile Off;
    

    Source of problem: VirtualBox Bug

    0 讨论(0)
提交回复
热议问题