以下是我的代码: -
projectDependencies.forEach((val)=>
{
container.register(val[0],function ()
{
return require(val[1]);
});
});
当我运行命令时,nodemon server.js我收到以下错误:
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()而不是()=&gt;然后一切正常。
答案 0 :(得分: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)'