Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Nextjs 14 and monday-sdk-js npm package = "TypeError: fetch is not a function" #143

Open
launchthatbrand opened this issue Mar 15, 2024 · 3 comments

Comments

@launchthatbrand
Copy link

Summary

I am working on an app for Monday.com api. It uses the "monday-sdk-js package".

I have it working fine on nextjs 13.4, but when I upgrade to Nextjs 14 I am getting this error. From what I can find there was something "node-fetch" related that was removed from Nextjs, potentionally causing this issue.

How can I go about making this package work? I assume by polyfilling node-fetch somehow but I am unclear on how to properly do this after searching.

The monday-sdk-js package has logic like:

import mondaySdk from "monday-sdk-js";
const monday = mondaySdk();
monday.setApiVersion("2023-10");

 const query = "query { boards (ids: 5798486455) { groups { title id }} }";
  const result = await monday.api(query, options);
  console.log("fetchCategories", result);

So in my component or server action I query the data, I never have direct access or actually write the fetch call. Inside the monday-sdk-js node_modules folder there is a file called "fetch.js" which has the fetch call and where the error is being thrown.

const fetch = require("node-fetch");

// for tests - to allow stubbing node-fetch with sinon
function nodeFetch(url, options = {}) {
  return fetch(url, options);
}

module.exports = {
  nodeFetch
};

How do i properly deal with this situation in NextJs 14?

Additional information

No response

Example

No response

@Sh1n
Copy link

Sh1n commented Apr 12, 2024

Same here

@launchthatbrand
Copy link
Author

Coming back to this, i believe I fixed with:

/**

  • Run build or dev with SKIP_ENV_VALIDATION to skip env validation. This is especially useful
  • for Docker builds.
    */
    await import("./src/env.js");

/** @type {import("next").NextConfig} */
const config = {
experimental: {
serverComponentsExternalPackages: ["monday-sdk-js"],
},
images: {
remotePatterns: [
{
hostname: "static.thenounproject.com",
},
{
hostname: "files-monday-com.s3.amazonaws.com",
},
{
hostname: "fdotwww.blob.core.windows.net",
},
],
},
};

export default config;

@pelykh
Copy link

pelykh commented Jul 11, 2024

Same problem. I fixed it with this:

//next.config.mjs

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: ["monday-sdk-js"],
  },
};

export default nextConfig;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants