Javascript 无效或意外的令牌 (\u0)

Javascript Invalid or Unexpected token (\u0)

正如您将在图像中看到的那样,有许多红点显然每个都标识为 \u0

文件内容或编辑器没有区别。

编译或不编译的 JS 文件没有区别,事实上,由于空格和换行,非压缩版本中出现更多红点,即使加载空白文件然后添加一些简单的东西,如 console.log('abc') 将只产生所有红点;

添加内容

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

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

正在删除内容

如果我启动 VM,然后从 JS 脚本中的任何位置删除字符,那么相同数量的字符将从文件的 webresponse 请求中的内容末尾消失。

未修改使用

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

结论

如果我在 VM 运行ning 期间以任何方式修改文件,结果就好像服务器以某种方式保留了服务器首次启动时文件字节大小的快照或者内容是最先提供的。然后在服务器正在 运行ning 时更改文件的内容,如果变小,它会切断内容,或者如果变大,则用 \u0 填充,就好像它正在填充文件一样。

可以清除故障不是永久性的

如果我在使文件损坏后重新启动 VM 并使用之前导致错误的修改刷新对 js 文件的请求,则错误消失并且我的新更改没有问题。

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

This issue only just started happening since the 18th November give or take a couple of days and I had been running the setup for over a month prior without issue, the only thing I remember changing recently is a couple of windows updates last week?

我在 运行ing Virtualbox VM Centos 7, Apache 2.4.6 + PHP 7.1.12 Windows 10 上使用 VBox Guest 安装到 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 设置(复制)

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

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

更新 1 - 26/11/17

我试过从头开始重建一个新的虚拟机,仍然是同样的问题。

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

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

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

添加一个名为class的测试:

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

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

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

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

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

注意评论前的测试 class 是如何缺失的,评论后出现了奇怪的字符。

然后我重新启动了虚拟机,然后在我的浏览器中按了 F5(刷新),字符消失了,我的测试 class 出现了:

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

我检查了 HTML 源代码响应,它是 而不是 对 PHP 的 HTML 输出执行此操作。

更新 2 - 26/11/17

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 引起的。

对于 NGINX 在位置/块中添加 sendfile off 设置。

location / {
    ...
    sendfile off;
}

对于Apache,在httpd.conf中寻找EnableSendfile并设置它至 关闭:

EnableSendfile off

您必须重新启动服务才能使更改生效,需要硬刷新您的网络浏览器 (CTRL+F5) 才能看到更改生效。

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.

您是否需要进入您的 VM 并进入您的服务器配置。 /etc/nginx/nginx.conf 并把 sendfile 关掉。

http {

    ##
    # Basic Settings
    ##

    sendfile off;
    ...
    }

错误与我相同 ( \u0 )。我被修复了

  1. sudo nano /etc/nginx/nginx.conf : 更改为关闭发送文件;
  2. 流浪者重新加载
  3. Ctrl + F5 (清除浏览器缓存) => 为我工作。