在 Nodejs 中导入 googleapis 会出错。如何使用 type:modules 正确导入 googleapis pakage.Iam
importing googleapis in Nodejs gives error. How to properly import googleapis pakage.Iam using type:modules
以下是我的导入和 google OAuth2 配置。但它给出的错误是:
ReferenceError: OAuth 未定义
import google from "googleapis";
let OAuth2 = google.auth.OAuth2;
const oauth2Client = new OAuth2(
MAILING_SERVICE_CLIENT_ID,
MAILING_SERVICE_CLIENT_SECRET,
MAILING_SERVICE_REFRESH_TOKEN,
SENDER_EMAIL_ADDRESS,
OAUTH_PLAYGROUND
);
如果 "type": "module"
在 package.json 中这样做:
import {google} from "googleapis";
其他
const {google} = require("googleapis");
以下是我的导入和 google OAuth2 配置。但它给出的错误是: ReferenceError: OAuth 未定义
import google from "googleapis";
let OAuth2 = google.auth.OAuth2;
const oauth2Client = new OAuth2(
MAILING_SERVICE_CLIENT_ID,
MAILING_SERVICE_CLIENT_SECRET,
MAILING_SERVICE_REFRESH_TOKEN,
SENDER_EMAIL_ADDRESS,
OAUTH_PLAYGROUND
);
如果 "type": "module"
在 package.json 中这样做:
import {google} from "googleapis";
其他
const {google} = require("googleapis");