Javascript无效或意外的令牌(\ u0) [英] Javascript Invalid or Unexpected token (\u0)

查看:287
本文介绍了Javascript无效或意外的令牌(\ u0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您将在图像中看到,有许多红点,每个红点显然标识为 \ u0

As you will see in the image there is a number of red dots that are apparently each identify as \u0

文件内容或编辑器没有影响.

正在编译或未编译的JS文件没有什么区别,实际上,由于空格和换行,在非缩小版本中会出现更多的红点,甚至是加载了空白文件,然后添加了诸如console.log('abc ')仅会导致所有红点;

The JS file being compiled or not compiled makes no difference, in fact more red dots appear in a non minified version because of spaces and new lines, even a blank file loaded and then adding something simple like console.log('abc') will result in all red dots only;

添加内容

这些不可见和无法选择的字符在文件末尾的出现次数与我在脚本的任何其他部分键入的任何其他字符的次数相同.

These invisible and unselectable characters appear the same number of times on the end of the file as the number of any other characters that I have typed out in any other part of the script.

仅在Web服务器提供服务的磁盘中,不可见字符本身不在磁盘上的实际文件中.

The invisible characters are not in the actual file itself on disk only in the one served by the web server.

删除内容

如果我启动VM,然后从JS脚本中的任意位置删除字符,则在文件的Webresponse请求中,相同数量的字符将从内容的结尾消失.

If i boot the VM and then delete characters out from anywhere in the JS script then the same number of chars will vanish from the END of the content in a webresponse request for the file.

未修改的用法

当我第一次启动VM并在浏览器中访问网站时,只要从未以任何方式修改文件,多次请求都不会出错.

When I first boot up the VM and visit the website in a browser there is no error ever on multiple requests as long as the file is never modified in any way.

结论

如果我在VM运行时以任何方式修改文件,结果就好像服务器以某种方式保留了服务器首次启动或首次提供内容时文件字节大小的快照.然后,在服务器运行时对文件内容进行更改后,要么减小内容的大小,要么切掉\ u0(如果增大的内容,就像填充文件一样).

If I modify the file in any way while the VM is running the result is as if the server has somehow kept a snapshot of what the byte size of the file was when the server either first booted or the content was first served. Then upon making alterations to the content of the file while the server is running it either chops off content if made smaller or pads out with \u0 if made bigger as if it is padding the file.

可以清除不持久的故障

如果我在使文件损坏后重新启动VM,并使用先前导致该错误的修改刷新对js文件的请求,则该错误消失了,我的新更改很好.

If I reboot the VM after making the file corrupt and refresh the request for the js file with the modifications that previously cause the error, the error is gone and my new changes are fine.

我还可以撤消破坏响应的最后更改,正常操作将继续.

I can also undo the last changes that corrupted the response and normal operation will continue.

这个问题从11月18日开始或仅仅花费了几天时间才开始发生,而我已经运行了一个多月的安装程序却没有出现问题,我记得最近唯一改变的就是几个 windows上周有更新?

我正在Windows 10上运行Virtualbox VM Centos 7,Apache 2.4.6 + PHP 7.1.12,并且使用VBox Guest Additions共享文件夹配置将源代码目录安装到VM.

I am running Virtualbox VM Centos 7, Apache 2.4.6 + PHP 7.1.12 on Windows 10 with the source code directory mounted to the VM using VBox Guest Additions shared folder configuration.

似乎此问题与VM有关,并且正在为 资产,如果文件在加载后发生更改,则以某种形式的填充和剔除.

It seems this issue is related to the VM and it's serving of the assets, some form of padding and culling if the file changed after being loaded.

重新启动httpd服务没有任何影响,只有在每次文件修改后清除问题后重新启动VM.

Restarting the httpd service has no affect, only rebooting the VM after every file modification clears the issue.

还有其他人遇到这个问题或能够重现它吗?

Has anyone else run into this problem or able to reproduce it?

VM设置(复制)

这是我在学习如何创建和运行本地开发环境时要建立的说明,如果您想尝试重现该问题:

Here are the instructions I have been building up as I learn how to create and run a local development environment if you want to try and reproduce the issue:

https://docs.google.com/document/d/11cBF75hfcehB3np4nlLhc1E

https://docs.google.com/document/d/11cBF75hfcehB3np4nlLhc1EqIOKVchKIuQJyrvn8ztk

更新1-26/11/17

我尝试从头开始重建新的虚拟机,仍然是同样的问题.

I have tried rebuilding a new VM from scratch, still same problem.

我注意到CSS文件也发生了这种情况,作为测试,我更改了以下代码:

I have noticed it is also happening to CSS files, as a test I changed the following code:

.flexData.tools .settings:hover {
    color: #0a0a0a;
}

/*# sourceMappingURL=flexData.css.map */

添加一个名为test的类:

to add a class called test:

.flexData.tools .settings:hover {
    color: #0a0a0a;
}
.test {
    color:blue;
}

/*# sourceMappingURL=flexData.css.map */

结果显示在服务器提供的文件末尾,如下所示:

Results in this at the end of the file served by the server looking like this:

.flexData.tools .settings:hover {
    color: #0a0a0a; 
}

/*# sourceMappingURL=flexData.css.map */
�������������������������

请注意,在注释之前如何丢失测试类,并且注释之后会出现奇怪的字符.

Notice how the test class is missing before the comment and the strange chars have appeared after the comment.

然后,我重新启动了VM,然后在浏览器中按了F5(刷新),字符消失了,并且出现了我的测试类:

Then I rebooted the VM then pressed F5 (refresh) in my browser, the chars vanish and my test class appears:

.flexData.tools .settings:hover {
    color: #0a0a0a; }
.test {
    color:blue;
}
/*# sourceMappingURL=flexData.css.map */

我检查了HTML源代码响应,这是对PHP的HTML输出执行的操作.

I checked the HTML source code response, it is not doing this to the HTML output from PHP.

更新2-26/11/17

我安装了XAMP并测试了上述所有问题...没有文件 修改导致错误,因此可以确认存在某种 VM或httpd服务在此处出现文件缓存问题 虚拟机.

I installed XAMP and tested all the issues above... None of the file modifications caused the error so this confirms there is some sort of file cache issue going here with the VM or the httpd service in the VM.

推荐答案

我遇到了同样的问题,这是由VM引起的.

I had the same issue, it's caused by the VM.

对于 NGINX ,在位置/块中添加关闭发送文件设置.

For NGINX in the location / block add the sendfile off setting.

location / {
    ...
    sendfile off;
}

对于 Apache ,在 httpd.conf 中查找 EnableSendfile ,并将其设置为 off :

For Apache, look for EnableSendfile in httpd.conf and set it to off:

EnableSendfile off

您必须重新启动服务才能使更改生效,必须在Web浏览器(CTRL + F5)中进行硬刷新才能看到更改.

You must restart the services for the changes to take effect, hard refresh in your web browser (CTRL+F5) is required to see the change in effect.

EnableMMAP和EnableSendfile:在支持该功能的系统上,可以使用内存映射或sendfile syscall来传递文件.通常,这可以提高服务器性能,但是从网络安装的文件系统提供服务时必须将其关闭,否则系统上对这些功能的支持就会中断.

EnableMMAP and EnableSendfile: On systems that support it, memory-mapping or the sendfile syscall may be used to deliver files. This usually improves server performance, but must be turned off when serving from networked-mounted filesystems or support for these functions is otherwise broken on your system.

这篇关于Javascript无效或意外的令牌(\ u0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆