[英]Why I am getting this error: declares '<MODULE>' locally, but it is not exported
I have a typescript file which exports a function to send emails using aws ses我有一个打字稿文件,它导出一个使用 aws ses 发送电子邮件的函数
//ses.tsx
let sendEmail = (args: sendmailParamsType) => {
let params = {
//here I get the params from args, then I send the email
};
return AWS_SES.sendEmail(params).promise();
};
module.exports = {
sendEmail
};
then somewhere else I have a next.js API endpoint page importing the module like this然后在其他地方我有一个 next.js API 端点页面,像这样导入模块
//index.tsx
import {sendEmail} from "../../../lib/ses";
the path is correct but the editor (phpstorm) highlight that line above in red and the error message is路径是正确的,但编辑器(phpstorm)以红色突出显示上面的那一行,错误消息是
declares 'sendEmail' locally, but it is not exported.
The path is correct and as you can see the module is exported.路径正确,您可以看到模块已导出。 When I execute the page I don't get any error but the email is not sent.
当我执行该页面时,我没有收到任何错误,但未发送电子邮件。
Also, I use the same module from another endpoint and it works.此外,我使用来自另一个端点的相同模块并且它可以工作。 Any suggestion to solve or debug this?
有什么建议可以解决或调试这个问题吗?
You're mixing up ES with CommonJS.您将 ES 与 CommonJS 混为一谈。
module.exports is used with require() //CommonJS Syntax module.exports 与 require() 一起使用 //CommonJS 语法
export is used with import //ES Syntax. export 与 import //ES 语法一起使用。
you can either export all the objects at once您可以一次导出所有对象
Oor you can simple export the object directly.或者您可以直接简单地导出对象。
Mail.tsx:邮件.tsx:
export const sendEmail = () => {}
main.tsx主要的.tsx
import {sendEmail} from "./Mail";
Also I recommend to use const instead of let for functions.我还建议使用 const 而不是 let 函数。
export default ...
also works, but may be used one time per file and can be imported with也可以,但每个文件可以使用一次,并且可以使用
import Mail from "./Mail.tsx";
Mail.sendEmail(...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.