我在 node js(07.10.19 的最新版本 node.js)应用程序中有一个 .ts 文件,它导入了没有默认导出的节点模块。我使用这种结构:import { Class } from 'abc';当我运行代码时,我有这个错误:Cannot use import statement outside a module。
在网络中,我看到了许多针对此问题的解决方案(针对 .js),但对我没有帮助,可能是因为我有打字稿文件。这是我的代码:
import { Class } from 'abc';
module.exports = { ...
execute(a : Class ,args : Array<string>){ ...
Run Code Online (Sandbox Code Playgroud)
这是我的 tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"strict": true
}
}
Run Code Online (Sandbox Code Playgroud) 我的 Firebase 功能有问题。我收到以下错误。
语法错误:不能在模块外使用导入语句
下面是我的代码:
import * as functions from 'firebase-functions';
import * as sgMail from '@sendgrid/mail';
sgMail.setApiKey(key);
export const weeklyReminder = functions.pubsub.schedule('every Wednesday 21:00').onRun(async context =>{
const msg = {
to: 'email@gmail.com',
...
};
return sgMail.send(msg);
});
Run Code Online (Sandbox Code Playgroud)
如何导入 firebase 函数?