2016-01-13 46 views
0

我使用nvm和試用-harmony標誌安裝了各種node.js版本,以使生成器函數與yield關鍵字一起工作,但在服務器啓動時出現各種錯誤。其中之一是如下:我如何使生成器函數與Hapi JS一起工作

/home/ubuntu/workspace/node_modules/hapi/node_modules/joi/lib/object.js:310                           
      throw castErr;                                        
       ^                                         
TypeError: Cannot read property '_items' of undefined                                 
    at /home/ubuntu/workspace/node_modules/hapi/node_modules/topo/lib/index.js:39:22                         
    at Array.forEach (native)                                       
    at internals.Topo.add (/home/ubuntu/workspace/node_modules/hapi/node_modules/topo/lib/index.js:36:24)                    
    at internals.Object.keys (/home/ubuntu/workspace/node_modules/hapi/node_modules/joi/lib/object.js:301:18)                   
    at internals.root.root.object (/home/ubuntu/workspace/node_modules/hapi/node_modules/joi/lib/index.js:71:72)                  
    at Object.<anonymous> (/home/ubuntu/workspace/node_modules/hapi/node_modules/catbox/lib/policy.js:255:24)                   
    at Module._compile (module.js:460:26)                                    
    at Object.Module._extensions..js (module.js:478:10)                                
    at Module.load (module.js:355:32)                                     
    at Function.Module._load (module.js:310:12) 

是否有什麼特殊的我需要做的使用yield關鍵字?

更新:我更新了nodejs到5.4.1,錯誤消失了。但是我不能使用yield函數。

這裏有一個代碼:

var nodes = yield Db.node.find({ type: 'root' }); 
return reply.success(nodes); 

這裏是我得到的錯誤:

var nodes = yield Db.node.find({ type: 'root' });                                
         ^^                                        

SyntaxError: Unexpected identifier 
+1

您使用的是哪個Node.JS版本? –

+0

因爲節點0.12根本不支持生成器,並且節點4.0和5.0不完全支持它。請參閱https://kangax.github.io/compat-table/es6/ –

+1

也可能包含一些失敗的代碼。 –

回答

相關問題