我正在尝试在Meteor中使用sendgrid
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"
}
答案 0 :(得分: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
,现在可以用于条件导入
答案 1 :(得分:0)
问题在于SendGrid SDK v6
requires Node.js version 6 and higher,但Meteor中捆绑的问题是4.8.4
:
$ meteor node --version
v4.8.4
正如this issue中所述,更新Node.js会有所帮助,但显然不能用Meteor完成。