0

我正在尝试sendgrid在 Meteor 中使用 npm 包(在服务器上):

const sendgridMail = require('@sendgrid/mail');

不断收到此错误:

(STDERR) packages\modules.js:961
(STDERR) const {
(STDERR)       ^
(STDERR)
(STDERR) SyntaxError: Unexpected token {
(STDERR)     at Object.exports.runInThisContext (vm.js:53:16)
(STDERR)     at D:\myProject\.meteor\local\build\programs\server\boot.js:331:30
(STDERR)     at Array.forEach (native)
(STDERR)     at Function._.each._.forEach (C:\Users\user1\AppData\Local\.meteor\packages\meteor-tool\1.5.2\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)

任何想法如何解决它?

更新: package.json包括以下依赖项:

"dependencies": {
    "@sendgrid/client": "^6.1.4",
    "@sendgrid/mail": "^6.1.4",
    "babel-runtime": "^6.20.0",
    "bcrypt": "^1.0.2",
    "body-parser": "^1.17.2",
    "card": "^2.3.0",
    "google-auth-library": "^0.10.0",
    "googleapis": "^21.3.0",
    "meteor-node-stubs": "~0.2.4",
    "moment": "^2.18.1",
    "pnotify": "^3.2.0",
    "shortid": "^2.2.8",
    "simpl-schema": "^0.3.1",
    "stripe": "^4.24.0"
}
4

2 回答 2

1

我这样使用它,发现它工作正常。

import sendgridModule from 'sendgrid';

let SEND_GRID_API_KEY = '';
try {
  SEND_GRID_API_KEY = Meteor.settings.env.SEND_GRID_API_KEY;
} catch (e) {
  // no-op
}
const sendgrid = sendgridModule(SEND_GRID_API_KEY);

我认为使用import代替require是首选,它现在可以用于条件导入

于 2017-09-29T09:09:54.177 回答
0

问题是SendGrid SDK v6 需要 Node.js 版本 6 及更高版本,但 Meteor 中捆绑的版本是4.8.4

$ meteor node --version
v4.8.4

本期所述,更新 Node.js 会有所帮助,但显然不能用 Meteor 完成。

我建议你使用sendgridnpm package,这个适用于 Node.js v4

于 2017-09-30T03:40:42.733 回答