我试图在 Windows 上运行closurebuilder.py,无论我通过什么文件,我都会从 Python 中得到相同的错误:
python goog\closure\bin\build\closurebuilder.py --root=goog/closure/goog/ --root=closurebuilder-example/ --namespace="myproject.start"
goog\closure\bin\build\closurebuilder.py: Scanning paths...
Traceback (most recent call last):
File "goog\closure\bin\build\closurebuilder.py", line 262, in <module>
main()
File "goog\closure\bin\build\closurebuilder.py", line 200, in main
sources.add(_PathSource(js_path))
File "goog\closure\bin\build\closurebuilder.py", line 175, in __init__
super(_PathSource, self).__init__(source.GetFileContents(path))
File "C:\Users\Chris\Code\Plain\goog\closure\bin\build\source.py", line 119, in GetFileContents
return fileobj.read()
File "C:\System\Python\33\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 6857: character maps to <undefined>
无论我是在尝试构建一个简单的脚本、一个空白文件还是更复杂的东西,都会发生这个抱怨字节为 0x8f 的 UnicodeDecodeError 的错误。我正在使用 Visual Studio 2012 创建这些文件,并且尝试使用其默认编码(Windows 代码页 1252)和 UTF-8 进行保存。
为了让事情变得简单,我试图在以下位置构建基本示例:https ://developers.google.com/closure/library/docs/closurebuilder
如果该页面发生变化,这里是我正在使用的 HTML 和脚本:
HTML:
<!doctype html>
<html>
<head>
<script src="../closure-library/closure/goog/base.js"></script>
<script src="start.js"></script>
</head>
<body>
<script>
myproject.start();
</script>
</body>
</html>
JS:
goog.provide('myproject.start');
goog.require('goog.dom');
myproject.start = function() {
var newDiv = goog.dom.createDom('h1', {'style': 'background-color:#EEE'},
'Hello world!');
goog.dom.appendChild(document.body, newDiv);
};
// Ensures the symbol will be visible after compiler renaming.
goog.exportSymbol('myproject.start', myproject.start);
这可能是什么原因造成的?