2017-09-05 13 views
-1

私はnode.jsにいます私は2つのファイルを持っています。require()の識別子が未定義として報告されます

winston.js:

class Winston { 
    constructor(count) { 
     this.count = count 
    } 
} 

start.js

const winston = require('./winston') 
let myWinston = new Winston(1) 

私はstart.js、(ノード./start.jsに)

を実行すると、私はエラーを取得します:

ReferenceError: Winston is not defined 

どのようにウィンストンファイルですか?

+0

他のファイルにexport defaultに必要な別のファイルから変数を取得する方法[これを試してみてくださいノードjsのファイル](https://stackoverflow.com/questions/7612011/how-to-get-a-variable-from-a-file-to-another-file-in-node-js) –

+0

最初に:あなた再インスタントWinston(タイトルケース)を起動し、winston(小文字)をインポートしています。 2番目:winston.jsからクラスをエクスポートする必要がある – Gerardo

答えて

-1

winston.js:

あなたはウィンストンクラスをエクスポートしませんでした。

export.defaults = class Winston { 
    constructor(count) { 
     this.count = count 
    } 
} 

start.js

あなたは必要なく、ウィンストンの結果を使用する必要があります。 Winston

// start.js 
const Winston = require('./winston') 
let myWinston = new Winston(1) 

const winston = require('./winston') 
let myWinston = winston(1) 
-1

キャップのためによく見るW、あなたは

// winston.js 
export default class Winston { 
    constructor(count) { 
     this.count = count 
    } 
} 
関連する問題