crisp-im / node-crisp-api

:zap: Crisp API Node Wrapper
https://docs.crisp.chat/guides/rest-api/
MIT License
99 stars 39 forks source link

NextJS Error #48

Open Mizerness opened 1 year ago

Mizerness commented 1 year ago

Hello,

I hope you are well. I was trying to connect crisp-api to my NextJS project.

However, I got several errors including the fact that it could not find the "dns" package. So I installed it

Here is the code (quite messy but just for testing)

/* Location: lib/c.js */

var Crisp = require("crisp-api");

var CrispClient = new Crisp();

export default CrispClient;
/* Location: components/Crisp/crisp.js */

import { CrispClient } from "../../lib/c.js";

export default function RunCrisp() {
  return (
    <div>
      {test}
    </div>
  );
}

export async function getStaticProps() {
  const identifier = "XXX-XXX-XXXX-XXX";
  const key =
    "XXX-XXX-XXXX-XXX";

  CrispClient.authenticateTier("plugin", identifier, key);

  var test = await CrispClient.website
    .listConversations("XXX-XXX-XXXX-XXX", 1)
    .then(function (conversations) {
      console.log("Listed conversations:", conversations);
    })
    .catch(function (error) {
      console.error("Error listing conversations:", error);
    });

  return {
    props: {
      test,
    },
  };
}
/* Location: pages/testcrisp.js */

import React from "react";
import RunCrisp from "../components/Crisp/crisp.js";

export default function TestCrisp() {
  return (
    <div>
      <RunCrisp />
    </div>
  );
}

And here is the error I have:

Screen Shot 2022-12-20 at 18 29 37

I try to do npm i dns but I just get another error saying that dgram is missing. What I see is that this package is deprecated.

Do you know what can I do to fix this ? Seems that some people using mongo-db package have the same issue.