![](/img/trans.png)
[英]Cannot build an app when there is CommonJS instead of ES6 module exports/imports
[英]When writing an ES6 module and converting to CommonJS, no specified exports are actually being exported
我有一個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和Node中。 Purescript報告未定義point
和pointToString
。 Node會話如下所示:
> require("./src/Page.js")
{}
> require("./src/Page.js").point
undefined
> require("./src/Page.js").pointToString
undefined
>
我完全不知所措。 我應該怎么做才能導出這兩個功能?
使用babel-cli以CommonJS格式創建一個適用於Node的模塊:
babel --presets=es2015 src/page.js > lib/Page.js
通常將編譯文件放入一個單獨的目錄是一個好主意。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.