【发布时间】:2016-01-22 20:32:08
【问题描述】:
我正在尝试将 ES6 imorts 与 babel 和 Node.js 一起使用
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
【问题讨论】:
-
你试过
export default function log() { ...吗? -
是的,我试过了。它不会改变任何事情。
-
你能指出博文中你看到函数被直接导入命名空间的地方吗?
-
如果您点击我的链接,您将直接滚动到正确的锚点“#import”
标签: javascript node.js import ecmascript-6