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

A Node.js API is used (MessageChannel) error when building nextjs app on docker #498

Open
ezeamin opened this issue Oct 30, 2024 · 2 comments

Comments

@ezeamin
Copy link

ezeamin commented Oct 30, 2024

Describe the feature / bug 📝:

These warnings show when building a nextjs app (v14), with npm, pnpm, and bun on a docker container (nextjs detects it as "edge", so it shows the messages).

home:build: ../../node_modules/scheduler/cjs/scheduler.production.min.js
home:build: A Node.js API is used (MessageChannel at line: 14) which is not supported in the Edge Runtime.
home:build: Learn more: https://nextjs.org/docs/api-reference/edge-runtime
home:build:
home:build: Import trace for requested module:
home:build: ../../node_modules/scheduler/cjs/scheduler.production.min.js
home:build: ../../node_modules/scheduler/index.js
home:build: ../../node_modules/react-dom/cjs/react-dom.production.min.js
home:build: ../../node_modules/react-dom/index.js
home:build: ../../node_modules/sonner/dist/index.mjs
home:build: ../../packages/utilities/src/getToken.ts
home:build: ../../packages/utilities/index.ts

I'm trying to replicate the bug in an independent project, but I can't find how. However, if it helps, I will leave here the getToken() code, where this error is showing according to the stacktrace.

import { toast } from 'sonner';

import { isClient } from './utils';
import { useSessionStore } from 'global-stores';

import type { GetTokenParams } from './interface';

export const getToken = async (params?: GetTokenParams): Promise<string> => {
  const { avoidRedirect = false, ignoreCurrentAT = false } = params ?? {};

  let token: string | null = null;

  // Token is available on client side store
  if (isClient() && !ignoreCurrentAT) {
    token = useSessionStore.getState().accessToken;
  }

  // Refresh token (Client side)
  if (isClient() && !token) {
    try {
      token = (await fetchTokenClient()).token;
    } catch (e) {
      if (avoidRedirect) return '';

      console.error('⚠️ Error fetching token, will redirect.', e);

      toast.error('Necesita volver a iniciar sesión');
      const currentLocation = window.location.pathname;

      setTimeout(() => {
        window.location.href = `/auth${currentLocation !== '/' ? `?redirectTo=${currentLocation}` : ''}`;
      }, 2000);
    }
  }

  // Refresh token (Server side)
  if (!isClient() && !token) {
    try {
      token = (await fetchTokenServer(ignoreCurrentAT)).token;
    } catch (e) {
      console.error('⚠️ Error fetching token', e);
    }
  }

  return token ?? '';
};
@ezeamin
Copy link
Author

ezeamin commented Oct 30, 2024

It also happens with:

home:build: ../../node_modules/scheduler/cjs/scheduler.production.min.js
home:build: A Node.js API is used (setImmediate at line: 11) which is not supported in the Edge Runtime.
home:build: Learn more: https://nextjs.org/docs/api-reference/edge-runtime

@emilkowalski
Copy link
Owner

Please provide a codesandbox demo with reproduction.

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

2 participants