语法错误:不能在模块外使用导入语句 nextjs Vercel

时间:2021-06-16 20:42:01

标签: javascript typescript next.js vercel

嗨,我需要一些帮助来将我的 nextjs 项目部署到 Vercel 我正在使用 emails-com 创建一个在本地完美运行的联系人,但我在 Vercel 上构建失败 当我像这样导入 emailjs-com 时: import emailjs from "emailjs-com"; 它在本地不起作用我得到 SyntaxError: Cannot use import statement outside a module 但后来我使用这个 var emailjs = require("emailjs-com"); 然后它在本地工作,但后来我得到一个构建错误 Type error: Cannot find module 'emailjs-com' or its corresponding type declarations.

我的代码:

import tw from "twin.macro";
import styled from "styled-components";
import emailjs from "emailjs-com";

const FormZ = () => {
 //  var emailjs = require("emailjs-com");
  
  const [status, setStatus] = useState("Send");
  const [userEmail, setUserEmail] = useState("");
  const [title, setTitle] = useState("");
  const [msg, setMsg] = useState("");
  const [name, setName] = useState("");
  var service_id = "*********";
  var template_id = "********";
  var user_id = "***********";
  var template_params = {
    userEmail: userEmail,
    subject: title,
    title: title,
    message: msg,
  };

  const handleSubmit = async (e) => {
    e.preventDefault();
    setStatus("Sending...");
    emailjs.send(service_id, template_id, template_params, user_id).then(
      function (response) {
        console.log("SUCCESS!", response.status, response.text);
        setStatus("Sent");
      },
      function (err) {
        console.log("FAILED...", err);
        setStatus("error in form");
      }
    );
  };

感谢所有帮助

0 个答案:

没有答案