Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在编写ES6模块并转换为CommonJS时,没有实际导出指定的导出_Javascript_Node.js_Ecmascript 6_Purescript - Fatal编程技术网

Javascript 在编写ES6模块并转换为CommonJS时,没有实际导出指定的导出

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

我有一个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;
        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,巴贝尔,鲍尔,纸浆工具链。