没有明显的原因导致“意外的标记非法”

时间:2022-06-16 22:44:17

I'm getting this JavaScript error on my console:

我的控制台上出现了一个JavaScript错误

Uncaught SyntaxError: Unexpected token ILLEGAL

未捕获的SyntaxError:意外的标记非法。

This is my code:

这是我的代码:

var foo = 'bar';​

It's super simple, as you can see. How could it be causing a syntax error?

这非常简单,正如你所看到的。它怎么会导致语法错误呢?

10 个解决方案

#1


479  

The error

When code is parsed by the JavaScript interpreter, it gets broken into pieces called "tokens". When a token cannot be classified into one of the four basic token types, it gets labelled "ILLEGAL" on most implementations, and this error is thrown.

当代码被JavaScript解释器解析时,它会被分解为“token”。当一个令牌不能被分类为四个基本令牌类型之一时,它在大多数实现上被贴上“非法”的标签,而这个错误被抛出。

The same error is raised if, for example, you try to run a js file with a rogue @ character, a misplaced curly brace, bracket, "smart quotes", single quotes not enclosed properly (e.g. this.run('dev1)) and so on.

例如,如果您试图运行一个带有流氓@字符的js文件,一个不恰当的花括号、括号、“智能引号”、单引号(例如this.run('dev1))等等,就会出现相同的错误。

A lot of different situations can cause this error. But if you don't have any obvious syntax error or illegal character, it may be caused by an invisible illegal character. That's what this answer is about.

很多不同的情况都会导致这个错误。但如果您没有任何明显的语法错误或非法字符,它可能是由一个不可见的非法字符造成的。这就是答案。

But I can't see anything illegal!

There is an invisible character in the code, right after the semicolon. It's the Unicode U+200B Zero-width space character (a.k.a. ZWSP, HTML entity ​). That character is known to cause the Unexpected token ILLEGAL JavaScript syntax error.

代码中有一个看不见的字符,在分号后面。它是Unicode U+200B零宽度空间字符(a.k.a。ZWSP, HTML entity ​)。已知该字符会导致意外的标记非法JavaScript语法错误。

And where did it come from?

I can't tell for sure, but my bet is on jsfiddle. If you paste code from there, it's very likely to include one or more U+200B characters. It seems the tool uses that character to control word-wrapping on long strings.

我不能肯定,但我赌的是jsfiddle。如果从那里粘贴代码,很可能包含一个或多个U+200B字符。似乎该工具使用这个字符来控制长字符串的文字包装。

UPDATE 2013-01-07

更新2013-01-07

After the latest jsfiddle update, it's now showing the character as a red dot like codepen does. Apparently, it's also not inserting U+200B characters on its own anymore, so this problem should be less frequent from now on.

在最新的jsfiddle更新之后,它现在显示了像codepen这样的红点。显然,它也不再自己插入U+200B字符了,所以从现在开始这个问题应该不那么频繁了。

UPDATE 2015-03-17

更新2015-03-17

Vagrant appears to sometimes cause this issue as well, due to a bug in VirtualBox. The solution, as per this blog post is to set sendfile off; in your nginx config, or EnableSendfile Off if you use Apache.

流浪汉似乎有时也会引起这个问题,因为在VirtualBox中有一个bug。解决方案,根据这篇博客文章,是设置sendfile关闭;在nginx配置中,如果使用Apache,也可以关闭它。

It's also been reported that code pasted from the Chrome developer tools may include that character, but I was unable to reproduce that with the current version (22.0.1229.79 on OSX).

也有报道说,从Chrome开发工具中粘贴的代码可能包含这个字符,但是我无法用当前版本(OSX上的22.0.1229.79)来复制这个字符。

How can I spot it?

The character is invisible, do how do we know it's there? You can ask your editor to show invisible characters. Most text editors have this feature. Vim, for example, displays them by default, and the ZWSP shows as <u200b>. You can also debug it online: jsbin displays the character as a red dot on its code panes (but seems to remove it after saving and reloading the page). CodePen.io also displays it as a dot, and keeps it even after saving.

这个角色是无形的,我们怎么知道它在那里?你可以让你的编辑去展示那些看不见的人物。大多数文本编辑器都有这个特性。例如,Vim默认显示它们,ZWSP显示为 。您还可以在网上调试它:jsbin在其代码窗格上显示了一个红点(但是在保存和重新加载页面之后似乎删除了它)。CodePen。io也将其显示为一个点,保存后保存。

Related problems

That character is not something bad, it can actually be quite useful. This example on Wikipedia demonstrates how it can be used to control where a long string should be wrapped to the next line. However, if you are unaware of the character's presence on your markup, it may become a problem. If you have it inside of a string (e.g., the nodeValue of a DOM element that has no visible content), you might expect such string to be empty, when in fact it's not (even after applying String.trim).

那个角色并不是什么坏事,它实际上是很有用的。在Wikipedia上的这个示例演示了如何使用它来控制将一个长字符串包到下一行的位置。但是,如果您不知道该字符在标记上的存在,它可能会成为一个问题。如果在字符串中有它(例如,DOM元素的nodeValue没有可见内容),那么您可能希望该字符串是空的,但实际上它不是(即使在应用string .trim之后)。

ZWSP can also cause extra whitespace to be displayed on an HTML page, for example when it's found between two <div> elements (as seen on this question). This case is not even reproducible on jsfiddle, since the character is ignored there.

ZWSP还可以在HTML页面上显示额外的空白,例如,在两个

元素之间(就像在这个问题上看到的)一样。这个例子甚至不能在jsfiddle上重现,因为这个角色在那里被忽略了。

Another potential problem: if the web page's encoding is not recognized as UTF-8, the character may actually be displayed (as ​ in latin1, for example).

另一个潜在的问题:如果web页面的编码是不被认为是utf - 8,显示的字符可能是(作为一个€喜爱在latin1,中的一个)。

If ZWSP is present on CSS code (inline code, or an external stylesheet), styles can also not be parsed properly, so some styles don't get applied (as seen on this question).

如果ZWSP存在于CSS代码(内联代码或外部样式表)中,样式也不能被正确解析,因此某些样式不会被应用(就像在这个问题上看到的那样)。

The ECMAScript Specification

I couldn't find any mention to that specific character on the ECMAScript Specification (versions 3 and 5.1). The current version mentions similar characters (U+200C and U+200D) on Section 7.1, which says they should be treated as IdentifierParts when "outside of comments, string literals, and regular expression literals". Those characters may, for example, be part of a variable name (and var x\u200c; indeed works).

在ECMAScript规范(版本3和5.1版本)中,我找不到任何关于这个特定字符的说明。当前版本在7.1节中提到了类似的字符(U+200C和U+200D),它们表示在“注释、字符串和正则表达式的外部”时,它们应该被视为标识符。例如,这些字符可能是变量名称的一部分(和var x\u200c;事实上工作)。

Section 7.2 lists the valid White space characters (such as tab, space, no-break space, etc.), and vaguely mentions that any other Unicode “space separator” (category “Zs”) should be treated as white space. I'm probably not the best person to discuss the specs in this regard, but it seems to me that U+200B should be considered white space according to that, when in fact the implementations (at least Chrome and Firefox) appear to treat them as an unexpected token (or part of one), causing the syntax error.

第7.2节列出了有效的空白字符(如选项卡、空格、无断点空间等),并含糊地提到任何其他Unicode“空间分隔符”(类别“Zs”)应该被当作空白。我可能不是最好的人,讨论这方面的规范,但在我看来,应该考虑U + 200 b显示空白,而事实上实现(至少Chrome和Firefox)似乎把他们当作一个意想不到的令牌(或部分),导致语法错误。

#2


61  

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

为什么要在代码中查找这个问题?甚至,如果是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.

如果您可以看到,在synced文件夹中保存文件之后发生了什么——您将看到文件末尾的*****。这与你的代码无关。

Solution.

解决方案。

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

如果你正在使用nginx在流浪箱-添加到服务器配置:

sendfile off;

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

如果您在流浪箱中使用apache -添加到服务器配置:

EnableSendfile Off;

Source of problem: VirtualBox Bug

问题来源:VirtualBox Bug。

#3


6  

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

如果您正在从另一个文档(比如PDF)中复制代码到您的控制台并尝试运行它,这也可能发生。

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.

我正试图从我正在阅读的Javascript书中运行一些示例代码,并且很惊讶它没有在控制台中运行。

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

显然,从PDF中复制会引入一些意外的、非法的和不可见的字符。

#4


5  

I got this error in chrome when I had an unterminated string after the line that the error pointed to. After closing the string the error went away.

我在chrome中得到了这个错误当我有一个未终止的字符串后,这个错误指向的线。关闭字符串后,错误消失了。

Example with error:

例子与错误:

var file = files[i]; // SyntaxError: Unexpected token ILLEGAL

jQuery('#someDiv').innerHTML = file.name + " (" + formatSize(file.size) + ") "
    + "<a href=\"javascript: something('"+file.id+');\">Error is here</a>";

Example without error:

示例没有错误:

var file = files[i]; // No error

jQuery('#someDiv').innerHTML = file.name + " (" + formatSize(file.size) + ") "
    + "<a href=\"javascript: something('"+file.id+"');\">Error was here</a>";

#5


4  

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.

我在mac电脑上遇到了同样的问题,因为mac用的是非法的javascript字符,取代了标准引号。

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).

为了解决这个问题,我必须更改我的mac系统的设置,即>键盘=>文本(tab),取消使用智能引号和dashes(默认检查)。

#6


3  

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.

如果您正在运行一个nginx + uwsgi设置漫游,那么主要的问题是在一些答案中提到的发送文件的虚拟盒错误。但是要解决它,您必须禁用nginx和uwsgi中的sendfile。

  1. In nginx.conf sendfile off

    nginx。参看sendfile掉

  2. uwsgi application / config --disable-sendfile

    uwsgi应用程序/配置——disable-sendfile。

#7


2  

When running OS X, the filesystem creates hidden forks of basically all your files, if they are on a hard drive that doesn't support HFS+. This can sometimes (happened to me just now) lead to your JavaScript engine tries to run the data-fork instead of the code you intend it to run. When this happens, you will also receive

当运行OS X时,文件系统会创建隐藏的基本上所有文件的分支,如果它们在一个不支持HFS+的硬盘上。这有时会(发生在我身上)导致你的JavaScript引擎试图运行数据叉而不是你想要运行的代码。当这种情况发生时,你也会收到。

SyntaxError: Unexpected token ILLEGAL

because the data fork of your file will contain the Unicode U+200B character. Removing the data fork file will make your script run your actual, intended code, instead of a binary data fork of your code.

因为文件的数据叉将包含Unicode U+200B字符。删除数据fork文件将使您的脚本运行实际的、预期的代码,而不是代码的二进制数据分支。

.whatever : These files are created on volumes that don't natively support full HFS file characteristics (e.g. ufs volumes, Windows fileshares, etc). When a Mac file is copied to such a volume, its data fork is stored under the file's regular name, and the additional HFS information (resource fork, type & creator codes, etc) is stored in a second file (in AppleDouble format), with a name that starts with ".". (These files are, of course, invisible as far as OS-X is concerned, but not to other OS's; this can sometimes be annoying...)

.无论如何:这些文件是在没有本机支持完整HFS文件特性(例如ufs卷、Windows文件共享等)的卷上创建的。当将Mac文件复制到这样一个卷中时,它的数据叉存储在文件的常规名称下,而附加的HFS信息(资源叉、类型和创建者代码等)存储在第二个文件中(在AppleDouble格式中),并以“。”开头。(当然,这些文件在OS- x上是看不见的,但对其他OS来说是不可见的;这有时候会让人讨厌……

#8


0  

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

我遇到了同样的问题,因为在文本字符串中添加代码时,我碰到了enter键。

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.

因为它是一长串文本,我想要看到它,而不需要在我的文本编辑器中滚动,然而,点击进入增加了一个看不见的字符的字符串,这是非法的。我用的是崇高的文本作为我的编辑。

#9


0  

I changed all space areas to &nbsp, just like that and it worked without problem.

我改变了所有的空间区域,就像这样,而且毫无问题。

val.replace(" ", "&nbsp");

val.replace(" "," ");

I hope it helps someone.

我希望它能帮助别人。

#10


0  

Here is my reason:

这是我的理由:

before:

之前:

var path = "D:\xxx\util.s"

which \u is a escape, I figured it out by using Codepen's analyze JS.

这是一种逃避,我用Codepen的分析JS找到了它。

after:

后:

var path = "D:\\xxx\\util.s"

and the error fixed

和错误的固定

#1


479  

The error

When code is parsed by the JavaScript interpreter, it gets broken into pieces called "tokens". When a token cannot be classified into one of the four basic token types, it gets labelled "ILLEGAL" on most implementations, and this error is thrown.

当代码被JavaScript解释器解析时,它会被分解为“token”。当一个令牌不能被分类为四个基本令牌类型之一时,它在大多数实现上被贴上“非法”的标签,而这个错误被抛出。

The same error is raised if, for example, you try to run a js file with a rogue @ character, a misplaced curly brace, bracket, "smart quotes", single quotes not enclosed properly (e.g. this.run('dev1)) and so on.

例如,如果您试图运行一个带有流氓@字符的js文件,一个不恰当的花括号、括号、“智能引号”、单引号(例如this.run('dev1))等等,就会出现相同的错误。

A lot of different situations can cause this error. But if you don't have any obvious syntax error or illegal character, it may be caused by an invisible illegal character. That's what this answer is about.

很多不同的情况都会导致这个错误。但如果您没有任何明显的语法错误或非法字符,它可能是由一个不可见的非法字符造成的。这就是答案。

But I can't see anything illegal!

There is an invisible character in the code, right after the semicolon. It's the Unicode U+200B Zero-width space character (a.k.a. ZWSP, HTML entity &#8203;). That character is known to cause the Unexpected token ILLEGAL JavaScript syntax error.

代码中有一个看不见的字符,在分号后面。它是Unicode U+200B零宽度空间字符(a.k.a。ZWSP, HTML entity ​)。已知该字符会导致意外的标记非法JavaScript语法错误。

And where did it come from?

I can't tell for sure, but my bet is on jsfiddle. If you paste code from there, it's very likely to include one or more U+200B characters. It seems the tool uses that character to control word-wrapping on long strings.

我不能肯定,但我赌的是jsfiddle。如果从那里粘贴代码,很可能包含一个或多个U+200B字符。似乎该工具使用这个字符来控制长字符串的文字包装。

UPDATE 2013-01-07

更新2013-01-07

After the latest jsfiddle update, it's now showing the character as a red dot like codepen does. Apparently, it's also not inserting U+200B characters on its own anymore, so this problem should be less frequent from now on.

在最新的jsfiddle更新之后,它现在显示了像codepen这样的红点。显然,它也不再自己插入U+200B字符了,所以从现在开始这个问题应该不那么频繁了。

UPDATE 2015-03-17

更新2015-03-17

Vagrant appears to sometimes cause this issue as well, due to a bug in VirtualBox. The solution, as per this blog post is to set sendfile off; in your nginx config, or EnableSendfile Off if you use Apache.

流浪汉似乎有时也会引起这个问题,因为在VirtualBox中有一个bug。解决方案,根据这篇博客文章,是设置sendfile关闭;在nginx配置中,如果使用Apache,也可以关闭它。

It's also been reported that code pasted from the Chrome developer tools may include that character, but I was unable to reproduce that with the current version (22.0.1229.79 on OSX).

也有报道说,从Chrome开发工具中粘贴的代码可能包含这个字符,但是我无法用当前版本(OSX上的22.0.1229.79)来复制这个字符。

How can I spot it?

The character is invisible, do how do we know it's there? You can ask your editor to show invisible characters. Most text editors have this feature. Vim, for example, displays them by default, and the ZWSP shows as <u200b>. You can also debug it online: jsbin displays the character as a red dot on its code panes (but seems to remove it after saving and reloading the page). CodePen.io also displays it as a dot, and keeps it even after saving.

这个角色是无形的,我们怎么知道它在那里?你可以让你的编辑去展示那些看不见的人物。大多数文本编辑器都有这个特性。例如,Vim默认显示它们,ZWSP显示为 。您还可以在网上调试它:jsbin在其代码窗格上显示了一个红点(但是在保存和重新加载页面之后似乎删除了它)。CodePen。io也将其显示为一个点,保存后保存。

Related problems

That character is not something bad, it can actually be quite useful. This example on Wikipedia demonstrates how it can be used to control where a long string should be wrapped to the next line. However, if you are unaware of the character's presence on your markup, it may become a problem. If you have it inside of a string (e.g., the nodeValue of a DOM element that has no visible content), you might expect such string to be empty, when in fact it's not (even after applying String.trim).

那个角色并不是什么坏事,它实际上是很有用的。在Wikipedia上的这个示例演示了如何使用它来控制将一个长字符串包到下一行的位置。但是,如果您不知道该字符在标记上的存在,它可能会成为一个问题。如果在字符串中有它(例如,DOM元素的nodeValue没有可见内容),那么您可能希望该字符串是空的,但实际上它不是(即使在应用string .trim之后)。

ZWSP can also cause extra whitespace to be displayed on an HTML page, for example when it's found between two <div> elements (as seen on this question). This case is not even reproducible on jsfiddle, since the character is ignored there.

ZWSP还可以在HTML页面上显示额外的空白,例如,在两个

元素之间(就像在这个问题上看到的)一样。这个例子甚至不能在jsfiddle上重现,因为这个角色在那里被忽略了。

Another potential problem: if the web page's encoding is not recognized as UTF-8, the character may actually be displayed (as ​ in latin1, for example).

另一个潜在的问题:如果web页面的编码是不被认为是utf - 8,显示的字符可能是(作为一个€喜爱在latin1,中的一个)。

If ZWSP is present on CSS code (inline code, or an external stylesheet), styles can also not be parsed properly, so some styles don't get applied (as seen on this question).

如果ZWSP存在于CSS代码(内联代码或外部样式表)中,样式也不能被正确解析,因此某些样式不会被应用(就像在这个问题上看到的那样)。

The ECMAScript Specification

I couldn't find any mention to that specific character on the ECMAScript Specification (versions 3 and 5.1). The current version mentions similar characters (U+200C and U+200D) on Section 7.1, which says they should be treated as IdentifierParts when "outside of comments, string literals, and regular expression literals". Those characters may, for example, be part of a variable name (and var x\u200c; indeed works).

在ECMAScript规范(版本3和5.1版本)中,我找不到任何关于这个特定字符的说明。当前版本在7.1节中提到了类似的字符(U+200C和U+200D),它们表示在“注释、字符串和正则表达式的外部”时,它们应该被视为标识符。例如,这些字符可能是变量名称的一部分(和var x\u200c;事实上工作)。

Section 7.2 lists the valid White space characters (such as tab, space, no-break space, etc.), and vaguely mentions that any other Unicode “space separator” (category “Zs”) should be treated as white space. I'm probably not the best person to discuss the specs in this regard, but it seems to me that U+200B should be considered white space according to that, when in fact the implementations (at least Chrome and Firefox) appear to treat them as an unexpected token (or part of one), causing the syntax error.

第7.2节列出了有效的空白字符(如选项卡、空格、无断点空间等),并含糊地提到任何其他Unicode“空间分隔符”(类别“Zs”)应该被当作空白。我可能不是最好的人,讨论这方面的规范,但在我看来,应该考虑U + 200 b显示空白,而事实上实现(至少Chrome和Firefox)似乎把他们当作一个意想不到的令牌(或部分),导致语法错误。

#2


61  

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

为什么要在代码中查找这个问题?甚至,如果是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.

如果您可以看到,在synced文件夹中保存文件之后发生了什么——您将看到文件末尾的*****。这与你的代码无关。

Solution.

解决方案。

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

如果你正在使用nginx在流浪箱-添加到服务器配置:

sendfile off;

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

如果您在流浪箱中使用apache -添加到服务器配置:

EnableSendfile Off;

Source of problem: VirtualBox Bug

问题来源:VirtualBox Bug。

#3


6  

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

如果您正在从另一个文档(比如PDF)中复制代码到您的控制台并尝试运行它,这也可能发生。

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.

我正试图从我正在阅读的Javascript书中运行一些示例代码,并且很惊讶它没有在控制台中运行。

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

显然,从PDF中复制会引入一些意外的、非法的和不可见的字符。

#4


5  

I got this error in chrome when I had an unterminated string after the line that the error pointed to. After closing the string the error went away.

我在chrome中得到了这个错误当我有一个未终止的字符串后,这个错误指向的线。关闭字符串后,错误消失了。

Example with error:

例子与错误:

var file = files[i]; // SyntaxError: Unexpected token ILLEGAL

jQuery('#someDiv').innerHTML = file.name + " (" + formatSize(file.size) + ") "
    + "<a href=\"javascript: something('"+file.id+');\">Error is here</a>";

Example without error:

示例没有错误:

var file = files[i]; // No error

jQuery('#someDiv').innerHTML = file.name + " (" + formatSize(file.size) + ") "
    + "<a href=\"javascript: something('"+file.id+"');\">Error was here</a>";

#5


4  

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.

我在mac电脑上遇到了同样的问题,因为mac用的是非法的javascript字符,取代了标准引号。

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).

为了解决这个问题,我必须更改我的mac系统的设置,即>键盘=>文本(tab),取消使用智能引号和dashes(默认检查)。

#6


3  

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.

如果您正在运行一个nginx + uwsgi设置漫游,那么主要的问题是在一些答案中提到的发送文件的虚拟盒错误。但是要解决它,您必须禁用nginx和uwsgi中的sendfile。

  1. In nginx.conf sendfile off

    nginx。参看sendfile掉

  2. uwsgi application / config --disable-sendfile

    uwsgi应用程序/配置——disable-sendfile。

#7


2  

When running OS X, the filesystem creates hidden forks of basically all your files, if they are on a hard drive that doesn't support HFS+. This can sometimes (happened to me just now) lead to your JavaScript engine tries to run the data-fork instead of the code you intend it to run. When this happens, you will also receive

当运行OS X时,文件系统会创建隐藏的基本上所有文件的分支,如果它们在一个不支持HFS+的硬盘上。这有时会(发生在我身上)导致你的JavaScript引擎试图运行数据叉而不是你想要运行的代码。当这种情况发生时,你也会收到。

SyntaxError: Unexpected token ILLEGAL

because the data fork of your file will contain the Unicode U+200B character. Removing the data fork file will make your script run your actual, intended code, instead of a binary data fork of your code.

因为文件的数据叉将包含Unicode U+200B字符。删除数据fork文件将使您的脚本运行实际的、预期的代码,而不是代码的二进制数据分支。

.whatever : These files are created on volumes that don't natively support full HFS file characteristics (e.g. ufs volumes, Windows fileshares, etc). When a Mac file is copied to such a volume, its data fork is stored under the file's regular name, and the additional HFS information (resource fork, type & creator codes, etc) is stored in a second file (in AppleDouble format), with a name that starts with ".". (These files are, of course, invisible as far as OS-X is concerned, but not to other OS's; this can sometimes be annoying...)

.无论如何:这些文件是在没有本机支持完整HFS文件特性(例如ufs卷、Windows文件共享等)的卷上创建的。当将Mac文件复制到这样一个卷中时,它的数据叉存储在文件的常规名称下,而附加的HFS信息(资源叉、类型和创建者代码等)存储在第二个文件中(在AppleDouble格式中),并以“。”开头。(当然,这些文件在OS- x上是看不见的,但对其他OS来说是不可见的;这有时候会让人讨厌……

#8


0  

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

我遇到了同样的问题,因为在文本字符串中添加代码时,我碰到了enter键。

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.

因为它是一长串文本,我想要看到它,而不需要在我的文本编辑器中滚动,然而,点击进入增加了一个看不见的字符的字符串,这是非法的。我用的是崇高的文本作为我的编辑。

#9


0  

I changed all space areas to &nbsp, just like that and it worked without problem.

我改变了所有的空间区域,就像这样,而且毫无问题。

val.replace(" ", "&nbsp");

val.replace(" "," ");

I hope it helps someone.

我希望它能帮助别人。

#10


0  

Here is my reason:

这是我的理由:

before:

之前:

var path = "D:\xxx\util.s"

which \u is a escape, I figured it out by using Codepen's analyze JS.

这是一种逃避,我用Codepen的分析JS找到了它。

after:

后:

var path = "D:\\xxx\\util.s"

and the error fixed

和错误的固定