Sendgrid-nodejs: 実行時のサンプルsendgridnode.jsコードの構文エラー。

作成日 2017年08月29日  ·  4コメント  ·  ソース: sendgrid/sendgrid-nodejs

問題の概要

サンプルのsendgridコードをコピーしてサーバーで実行しようとすると、mail.jsで構文エラーが発生します。

再現する手順

  1. npm install @ sendgrid / mail
  2. bash環境にエクスポートされた環境変数SENDGRID_API_KEY
  3. サンプルコードをコピーしました
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: '[email protected]',
  from: '[email protected]',
  subject: 'Sending with SendGrid is Fun',
  text: 'and easy to do anywhere, even with Node.js',
  html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg);

最後のステップ:
コードを実行する

# node sendgrid.js
/root/scripts/node_modules/@sendgrid/mail/src/mail.js:6
const {
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/root/scripts/sendgrid.js:1:78)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

技術的な詳細:

# npm list |grep sendgrid
├─┬ @sendgrid/[email protected]
│ ├─┬ @sendgrid/[email protected]
│ │ ├── @sendgrid/[email protected] deduped
│ └─┬ @sendgrid/[email protected]
├─┬ [email protected]
│ └── [email protected]
npm ERR! extraneous: [email protected] /root/scripts/node_modules/jsprim/node_modules/assert-plus
npm ERR! extraneous: [email protected] /root/scripts/node_modules/verror/node_modules/assert-plus
npm ERR! extraneous: [email protected] /root/scripts/node_modules/dashdash/node_modules/assert-plus
npm ERR! extraneous: [email protected] /root/scripts/node_modules/getpass/node_modules/assert-plus
npm ERR! extraneous: [email protected] /root/scripts/node_modules/sshpk/node_modules/assert-plus
# npm -v 
5.3.0
# node -v
v4.8.4
# echo $SENDGRID_API_KEY
SG.jyr8dVjFTBO4MayuTAS_zA.7a9Qg_XXXXXX
help wanted question

最も参考になるコメント

こんにちは@kiranshashiny

このSDKのv6はノードv4をサポートしていないため、これは機能していないと思います。

Node v6以降を使用するマシンにアクセスできますか?

敬具、

エルマー

全てのコメント4件

こんにちは@kiranshashiny

このSDKのv6はノードv4をサポートしていないため、これは機能していないと思います。

Node v6以降を使用するマシンにアクセスできますか?

敬具、

エルマー

これは正しいです。ノード4でサポートされていない破壊ステートメントでエラーが発生しています。

ノード8.xにアップグレードしましたが、機能します。

修正はアップグレードであったため、問題を解決しました。

このページは役に立ちましたか?
0 / 5 - 0 評価