2017-11-04 12 views
0

以下は、私のコードです: - :入手 "エラー:関数の引数を(解析できませんでした)=>"

私は以下のエラーを取得していますserver.js nodemon

projectDependencies.forEach((val)=> 
{ 
    container.register(val[0],function() 
    { 
     return require(val[1]); 
    }); 
}); 

私はコマンドを実行している間、

Error: could not parse function arguments:()=> 
{ 
    return container; 
} 
    at argList (C:\Users\Data-Vinci\Desktop\JS\chatapp\node_modules\dependable\index.js:97:15) 
    at toFactory (C:\Users\Data-Vinci\Desktop\JS\chatapp\node_modules\dependable\index.js:82:21) 
    at registerOne (C:\Users\Data-Vinci\Desktop\JS\chatapp\node_modules\dependable\index.js:33:32) 
    at Object.register (C:\Users\Data-Vinci\Desktop\JS\chatapp\node_modules\dependable\index.js:26:16) 
    at Object.<anonymous> (C:\Users\Data-Vinci\Desktop\JS\chatapp\container.js:22:11) 
    at Module._compile (module.js:569:30) 
    at Object.Module._extensions..js (module.js:580:10) 
    at Module.load (module.js:503:32) 
    at tryModuleLoad (module.js:466:12) 
    at Function.Module._load (module.js:458:3) 

私のコードは構文的に正しいと思います。問題がどこにあるのか分からない。

注: - ただし、()=の代わりにfunction()を使用すると、すべて正常に動作します。

答えて

0

dependable.argListは、関数を文字列に変換し、arg名を解析します。矢印関数は、それが探しているものに文字列化しません。

https://github.com/Schoonology/dependable/blob/master/index.coffee#L63

match = func.toString().match /function.*?\(([\s\S]*?)\)/ 
if not match? then throw new Error "could not parse function arguments: #{func?.toString()}" 

例えば

> func = function(val){ console.log(val); } 
> func.toString() 
'function (val){ console.log(val); }' 

> arrowFunc = (val) => console.log(val); 
> arrowFunc.toString(); 
'(val) => console.log(val)' 
関連する問題