在编写ES6模块并转换为CommonJS时,实际上不会导出指定的导出

我有一个ES6模块,我试图导出几个函数。 最终目标是导入到purescript中,但是现在我所谓的导出函数甚至不会出现在Node中,我不明白为什么。

这里是模块:

"use strict"; const point = (x, y) => new Point(x, y) const pointToString = (point) => point.toString() class Point { constructor(x, y) { this.x = x; this.y = y; } toString () { return `(${this.x}, ${this.y})`; } } export { point, pointToString } 

我像这样进行传译:

 browserify src/page.js -t [ babelify --presets [es2015] ] > src/Page.js 

然后我尝试加载到Purescript和节点。 Purescript报告pointpointToString没有定义。 节点会话如下所示:

 > require("./src/Page.js") {} > require("./src/Page.js").point undefined > require("./src/Page.js").pointToString undefined > 

我完全亏损。 我应该怎么做才能让这两个函数导出?

使用babel-cli创buildCommonJS格式的模块适合Node:

babel --presets=es2015 src/page.js > lib/Page.js

将编译的文件放入一个单独的目录通常是一个好主意。