我试图使用ES6 imorts与巴贝尔和Node.js的ES6进口“模块”不给的存取权限“模块”
import "./utils.js";
log("something"); //throw an error : log is not defined
我utils.js
看起来像这样的功能:
function log(... params){
console.log(... params);
}
log("module utils executed");
//Is executed and display "module utils executed" in the console.
我也尝试使用export function log(... params)
和export default log(... params)
但它不起作用。
所以我不明白这是怎么猜想作品...
编辑:
我知道的其他方式进口是做import utils from "./utils.js"
但它不是我想。我希望能够使用log()
而不用前缀模块变量名称。像this blog post
你试过'导出默认函数日志(){...'? –
是的,我尝试过。它不会改变任何事情。 –
您可以指向博客文章中您看到函数直接导入到命名空间中的位置吗? –