2016-08-20 50 views
2

在預ES6,我這是怎麼導入connect-mongo(會話):ES6 - 如何導入connect-mongo(會話)?

var MongoStore = require("connect-mongo")(session); 

但我怎麼可以導入它ES6?

import MongoStore from 'connect-mongo'; 
let monStore = MongoStore(session); 

錯誤:

const Store = connect.Store || connect.session.Store; 
               ^

TypeError: Cannot read property 'Store' of undefined 

任何想法?

回答

1

你可以嘗試導入這樣的:

import * as connectMongo from 'connect-mongo'; 

const MongoStore = connectMongo(session); 

從MDN文檔

Import an entire module's contents. This inserts myModule into the current scope, containing all the exported bindings from "my-module.js".

import * as myModule from "my-module";

More information can be found here.

+0

感謝您的答案,但我有這樣的錯誤:'VAR MongoStore = connectMongo(_expressSession2 。默認); ^ TypeError:connectMongo不是函數 ' – laukok

+0

嘗試使用同樣的方法導入會話嗎? – alexi2

+0

抱歉,你的意思是? – laukok