如何将需求转换为es6中的import语句

时间:2016-09-01 14:07:38

标签: javascript import require

我想让它在firebase中运行:

var FirebaseTokenGenerator = require("firebase-token-generator");
var tokenGenerator = new FirebaseTokenGenerator("<YOUR_FIREBASE_SECRET>");
var token = tokenGenerator.createToken({ uid: "1", some: "arbitrary", data: "here" });

但是我得到require is not defined error

然后切换到:

import FirebaseTokenGenerator from("firebase-token-generator");
  var tokenGenerator = new FirebaseTokenGenerator("<YOUR_FIREBASE_SECRET>");
  var token = tokenGenerator.createToken({ uid: "uniqueId1", some: "arbitrary", data: "here" });

我得到Uncaught SyntaxError: Unexpected token import

为什么这会失败,我是否获得了导入权?

0 个答案:

没有答案