0

我正在尝试使用Compiling Application with Closure Compiler 教程在 Windows 7 上构建 openlayers-3 的自定义应用程序。运行closure-util 构建选项时,我得到以下信息:

C:\Roy\websites\php_js_projects\closure-compiler>node_modules\openlayers\node_mo
dules\.bin\closure-util build config.json app.js
info closure-util Reading build config
info closure-util Getting Closure dependencies
info closure-util Compiling 367 sources
child_process.js:1162
    throw errnoException(err, 'spawn');
          ^
Error: spawn ENAMETOOLONG
    at exports._errnoException (util.js:746:11)
    at ChildProcess.spawn (child_process.js:1162:11)
    at Object.exports.spawn (child_process.js:995:9)
    at Object.module.exports [as compile] (C:\Roy\websites\php_js_projects\closu
re-compiler\node_modules\openlayers\node_modules\closure-util\lib\compile.js:42:
18)
    at compile (C:\Roy\websites\php_js_projects\closure-compiler\node_modules\op
enlayers\node_modules\closure-util\lib\build.js:94:11)
    at fn (C:\Roy\websites\php_js_projects\closure-compiler\node_modules\openlay
ers\node_modules\closure-util\node_modules\async\lib\async.js:579:34)
    at Immediate._onImmediate (C:\Roy\websites\php_js_projects\closure-compiler\
node_modules\openlayers\node_modules\closure-util\node_modules\async\lib\async.j
s:495:34)
    at processImmediate [as _immediateCallback] (timers.js:358:17)

我没有找到讨论这个问题的谷歌网络搜索或搜索。有解决方法吗?

4

1 回答 1

0

我今天遇到了这个确切的问题并找到了解决方法。我认为问题在于 OpenLayers 3 附带了一个过时版本的closure-util,在其package.json. 在 OpenLayers 开发人员自己指定较新版本之前,我发现将closure-util 切换到最新版本为我解决了这个问题。


解决方法:

在 OpenLayers 目录下执行以下所有操作(您的情况似乎C:\Roy\websites\php_js_projects\closure-compiler\node_modules\openlayers如此)。为了保持一致性,我将以下示例引用到您的路径:

  1. 打开package.json,查找该"dependencies"部分并将closure-util 的版本从1.5.0 更改为更新的版本(在撰写本文时最新版本为1.7.0)。

    "dependencies": {
        ..
        "closure-util": "1.5.0",
        ..
    },
    

    变成

    "dependencies": {
        ..
        "closure-util": "1.7.0",
        ..
    },
    
  2. 通过从目录中删除整个closure-util目录来删除旧版本的closure-util node_modules。(在你的情况下删除C:\Roy\websites\php_js_projects\closure-compiler\node_modules\openlayers\node_modules\closure-util。)

  3. npm install在目录内运行openlayers。这将使节点包管理器自动检索最新版本的closure-util来替换我们在上一步中删除的那个。

    C:\Roy\websites\php_js_projects\closure-compiler\node_modules\openlayers>npm install
    -
    > ws@0.4.32 install C:\Roy\websites\php_js_projects\closure-compiler\node_modules\openlayers\node_modules\closure-util\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws
    ..snip..
    > closure-util@1.7.0 postinstall C:\Roy\websites\php_js_projects\closure-compiler\node_modules\openlayers\node_modules\closure-util
    > node ./bin/closure-util.js update
    
    info install Downloading http://dl.google.com/closure-compiler/compiler-20150729.zip
    ..snip..
    
  4. 再次尝试您的构建。

    C:\Roy\websites\php_js_projects\closure-compiler>node_modules\openlayers\node_modules\.bin\closure-util build config.json app.js
    
于 2015-09-04T18:34:55.243 回答