【问题标题】:Error when trying to use LESS on file://尝试在 file:// 上使用 LESS 时出错
【发布时间】:2016-08-23 20:46:02
【问题描述】:

当我尝试在 google chrome 上使用我的 LESS 文件时,它会在控制台上显示此错误:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
less.js:446 XMLHttpRequest cannot load file:///path/core.less. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

我已经下载了less.js,并将其放入如下所示的脚本标签中

head class="Setup">
    <!-- LESS -->
    <link rel="stylesheet/less" type="text/css" href="path/core.less"/>
    <script src="path/less.js" type="text/javascript"></script>

但是,如果我为我的文本编辑器使用一个包,即https://atom.io/packages/browser-plus,它可以正常工作。控制台日志:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
less.js:837 rendered file:///path/core.less successfully.
less.js:837 css for file:///path/core.less generated in 67ms
less.js:837 less has finished. css generated in 67ms

检查 Google Chrome 版本后,文本编辑器使用版本 47,而我的普通 chrome 使用版本 50。我不知道发生了什么。有解决办法吗?

编辑:找到less.js not working in chrome 由于我不知道如何设置 Apache,我尝试搜索如何创建命令行开关,而我使用的是 mac,结果显示了 windows 结果。

【问题讨论】:

标签: css google-chrome less


【解决方案1】:

您已正确识别,LESS.js 无法与 Chrome 中的 file:// URL 方案一起使用:

附言如果您正在使用 Less.js 浏览器脚本,目前将无法使用 Chrome 和您页面的路径以“file:///”开头,因为已知 Chrome 问题。

由于您运行的是 Mac OSX,我建议您安装 MAMP,因为它可以让您省去为您设置本地服务器的麻烦:

https://www.mamp.info/en/

【讨论】:

  • 谢谢!我从不知道 MAMP 的存在,如果没有其他选择,我什至不知道如何使用文档,它为我设置 Apache 节省了很多精力。
猜你喜欢
  • 2013-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-09
  • 2018-01-11
  • 2015-10-20
  • 2020-12-14
  • 1970-01-01
相关资源
最近更新 更多