serwist icon indicating copy to clipboard operation
serwist copied to clipboard

[Bug]: Vercel build fails to load next.config.js

Open empz opened this issue 1 year ago • 8 comments

Provide environment information

Next.js 14.2.3 @serwist/next: 9.0.2

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

Will include later

To reproduce

  1. Create a T3-App
bun create t3-app@latest
  1. Follow the steps described here: https://serwist.pages.dev/docs/next/getting-started

  2. Deploy to Vercel

Describe the bug

Building the app locally works fine, but building in Vercel fails with the following logs/error:

[01:02:29.465]  ⨯ Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
[01:02:29.471] 
[01:02:29.472] > Build error occurred
[01:02:29.473] file:///vercel/path0/node_modules/glob/dist/esm/pattern.js:2
[01:02:29.473] import { GLOBSTAR } from 'minimatch';
[01:02:29.473]          ^^^^^^^^
[01:02:29.473] SyntaxError: Named export 'GLOBSTAR' not found. The requested module 'minimatch' is a CommonJS module, which may not support all module.exports as named exports.
[01:02:29.473] CommonJS modules can always be imported via the default export, for example using:
[01:02:29.473] 
[01:02:29.474] import pkg from 'minimatch';
[01:02:29.474] const { GLOBSTAR } = pkg;
[01:02:29.474] 
[01:02:29.474]     at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
[01:02:29.474]     at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
[01:02:29.474]     at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
[01:02:29.474]     at async loadConfig (/vercel/path0/node_modules/next/dist/server/config.js:698:36)
[01:02:29.474]     at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:154:20)
[01:02:29.474]     at async /vercel/path0/node_modules/next/dist/build/index.js:372:28
[01:02:29.474]     at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:154:20)
[01:02:29.474]     at async build (/vercel/path0/node_modules/next/dist/build/index.js:366:9)
[01:02:29.480] error: script "vercel-build" exited with code 1
[01:02:29.484] Error: Command "bun run vercel-build" exited with 1

Expected behavior

It should build.

Screenshots (if relevant)

No response

Additional information (if relevant)

next.config.js

import withSerwistInit from "@serwist/next";

const withSerwist = withSerwistInit({
  // Note: This is only an example. If you use Pages Router,
  // use something else that works, such as "service-worker/index.ts".
  swSrc: "src/app/sw.ts",
  swDest: "public/sw.js",
});

/**
 * 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 = {};

export default withSerwist(config);

Everything else is the default from create-t3-app.

empz avatar May 16 '24 23:05 empz

Sounds like it might be a package resolution issue with serwist + bun. Got multiple projects running serwist (of which, atleast 4 of em are started from the t3-app startingpoint) and when using any other package manager, all is fine.

JesseKoldewijn avatar May 17 '24 11:05 JesseKoldewijn

Seems that glob/minimatch's ESM/CJS hybrid support might be a bit weird. Suggest you open a new issue over there!

DuCanhGH avatar May 20 '24 15:05 DuCanhGH

same issue with t3 and bun on Vercel

andy5090 avatar May 25 '24 17:05 andy5090

same issue with t3 and bun on Vercel

aka, same as OP...

JesseKoldewijn avatar May 25 '24 19:05 JesseKoldewijn

I have the same issue with

"next": "^14.3.0-canary.79"
"@serwist/next": "^9.0.2",

But I managed to work it around by running:

bun i minimatch@latest

and amending package.json with

"overrides": {
    "minimatch": "$minimatch"
}

There are still warnings. But at least I can build the project, while waiting for the proper fix in @serwist/next

mrkosima avatar Jun 08 '24 21:06 mrkosima

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jul 09 '24 02:07 github-actions[bot]

experiencing a similar issue, though it seems to happen on some builds and not others. anyone got a workaround?

szamanr avatar Sep 05 '24 09:09 szamanr

experiencing a similar issue, though it seems to happen on some builds and not others. anyone got a workaround?

As mentioned in previous comments on this issue, this seems to be a bun specific issue. This is probably related to package resolution, meaning the only workaround would be to not use bun.

JesseKoldewijn avatar Sep 05 '24 21:09 JesseKoldewijn

image

Just a heads-up—I seem to be able to install Serwist with Bun on Vercel now. Probably time to close this issue? :)

DuCanhGH avatar Dec 06 '24 13:12 DuCanhGH

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jan 06 '25 02:01 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jan 21 '25 02:01 github-actions[bot]

@DuCanhGH what did you do to get it to work properly?

yungyoda avatar Mar 06 '25 00:03 yungyoda

@yungyoda nothing special. Just deploy it like normal.

DuCanhGH avatar Mar 06 '25 00:03 DuCanhGH