Javascript 在编写ES6模块并转换为CommonJS时,没有实际导出指定的导出
我有一个ES6模块,我正试图从中导出几个函数。最终的目标是导入到purescript中,但现在我假定导出的函数甚至没有出现在节点中,我无法理解为什么 以下是模块:Javascript 在编写ES6模块并转换为CommonJS时,没有实际导出指定的导出,javascript,node.js,ecmascript-6,purescript,Javascript,Node.js,Ecmascript 6,Purescript,我有一个ES6模块,我正试图从中导出几个函数。最终的目标是导入到purescript中,但现在我假定导出的函数甚至没有出现在节点中,我无法理解为什么 以下是模块: "use strict"; const point = (x, y) => new Point(x, y) const pointToString = (point) => point.toString() class Point { constructor(x, y) { this.x = x
"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和Node中。Purescript报告未定义点
和点字符串
。节点会话如下所示:
> require("./src/Page.js")
{}
> require("./src/Page.js").point
undefined
> require("./src/Page.js").pointToString
undefined
>
我完全不知所措。要导出这两个函数,我应该做些什么?使用以CommonJS格式创建适合节点的模块:
babel--presets=es2015 src/page.js>lib/page.js
通常,将编译后的文件放在一个单独的目录中是一个好主意。manual
browserify
command来生成页面。jso抱歉,我没有意识到。您看过生成的代码了吗?通常是的。这是原型设计。我还必须弄清楚npm,巴贝尔,鲍尔,纸浆工具链。