Critical dependency: the request of a dependency is an expression

I’m using EnvironmentVariablesManager from the @mondaycom/apps-sdk npm package (latest version 3.0.11).
In a Typescript file auth.ts, I’m trying to read environment variables to initialize NextAuth (v5, beta) which I’m using to authenticate the user to my app.

import NextAuth from "next-auth";
import { EnvironmentVariablesManager } from "@mondaycom/apps-sdk";

new EnvironmentVariablesManager({ updateProcessEnv: true });

export const { auth, handlers, signIn, signOut } = NextAuth({
  ...
}

This compilation error occurs:

./node_modules/app-root-path/lib/app-root-path.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/app-root-path/lib/app-root-path.js
./node_modules/app-root-path/index.js
./node_modules/@mondaycom/apps-sdk/dist/esm/utils/local-db.js
./node_modules/@mondaycom/apps-sdk/dist/esm/secure-storage/secure-storage.local.js
./node_modules/@mondaycom/apps-sdk/dist/esm/secure-storage/index.js
./node_modules/@mondaycom/apps-sdk/dist/esm/index.js
./src/auth.ts
./src/app/layout.tsx

How do I fix this?

Hello there @ngruson,

I believe this problem might not be connected to monday itself. I found a few links with possible solutions that worked for other users (disclaimer: This is not a recommendation, it is just what I could find about it):

Link 1
Link 2
Link 3
Link 4
Link 5

I hope you find the solution!

Cheers,
Matias

Agreed that it’s not a problem of the Monday platform.
The problem was just related to the way that Next.js is bundling npm packages.
I found a solution, I changed the next.config.mjs file in my app.

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

export default nextConfig;

Reference:
next.config.js Options: serverComponentsExternalPackages | Next.js (nextjs.org)

Now my app compiles again.

That is great @ngruson!

Thank you for sharing this!