Build fails after upgrading to Next.js 14 (webpack issues) - Works fine in dev mode #57535
Replies: 20 comments 30 replies
-
Hey @MartinXPN could add some piece of code causing this issue? |
Beta Was this translation helpful? Give feedback.
-
Happens to me too. I also use Firebase and Firebase admin packages. Have been using latest Next 13 in production since May and it's been working great. |
Beta Was this translation helpful? Give feedback.
-
Could you try to turn of swcMinify and see if the issue persists? |
Beta Was this translation helpful? Give feedback.
-
I tried reproducing this on a smaller project but with no luck so far. I've tried integrating Below are the details of the crashing project (the one that is not possible to build). Here is my {
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/cache": "^11.11.0",
"@emotion/css": "^11.11.0",
"@emotion/react": "^11.11.0",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@hookform/resolvers": "^3.3.2",
"@matejmazur/react-katex": "^3.1.3",
"@mui/icons-material": "^5.14.15",
"@mui/material": "^5.14.15",
"@mui/x-date-pickers": "^6.16.3",
"@mui/x-tree-view": "^6.0.0-beta.0",
"@sentry/nextjs": "^7.75.1",
"@svgr/webpack": "^8.1.0",
"ace-builds": "^1.31.0",
"algoliasearch": "^4.20.0",
"axios": "^1.6.0",
"clipboard-copy": "^4.0.1",
"cookies-next": "^4.0.0",
"encoding": "^0.1.13",
"endent": "^2.1.0",
"firebase": "^10.5.2",
"firebase-admin": "^11.11.0",
"firebaseui": "^6.1.0",
"katex": "^0.16.9",
"moment": "^2.29.4",
"next": "^14.0.0",
"next-firebase-auth-edge": "^0.9.0",
"notion-client": "^6.16.0",
"notion-types": "^6.16.0",
"prismjs": "^1.29.0",
"react": "^18.2.0",
"react-ace": "^10.1.0",
"react-calendar-heatmap": "^1.9.0",
"react-countdown": "^2.3.5",
"react-dom": "^18.2.0",
"react-drag-drop-files": "^2.3.10",
"react-hook-form": "^7.47.0",
"react-hotkeys-hook": "^4.4.1",
"react-intersection-observer": "^9.5.2",
"react-markdown": "^9.0.0",
"react-multi-split-pane": "^0.3.3",
"react-notion-x": "^6.16.0",
"react-slick": "^0.29.0",
"react-spring": "^9.7.3",
"recharts": "^2.9.0",
"sharp": "^0.32.6",
"slick-carousel": "^1.8.1",
"superjson": "^2.2.0",
"typescript": "^5.2.2",
"use-async-effect": "^2.2.7",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^20.8.9",
"@types/prismjs": "^1.26.2",
"@types/react": "^18.2.33",
"@types/react-calendar-heatmap": "^1.6.5",
"@types/react-dom": "^18.2.14",
"@types/react-slick": "^0.23.11",
"eslint": "^8.52.0",
"eslint-config-next": "^14.0.0"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
}
} Here is my {
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [{"name": "next"}],
},
"include": [
"next-env.d.ts", ".next/types/**/*.ts", "middleware.ts",
"src/**/*", "app/**/*", "@types/**/*", "server/**/*"
],
"exclude": ["node_modules", "**/*.spec.ts", "lib"]
} And here is my const {withSentryConfig} = require('@sentry/nextjs');
module.exports = withSentryConfig({
reactStrictMode: true,
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"]
});
return config;
},
images: {
remotePatterns: [{
protocol: 'https',
hostname: '**.notion.so',
}, {
protocol: 'https',
hostname: '**.amazonaws.com',
}, {
protocol: 'https',
hostname: '**.googleapis.com',
}],
domains: ['flagcdn.com'],
formats: ['image/avif', 'image/webp'],
minimumCacheTTL: 60 * 60, // cache for 1h
}
},
// Injected content via Sentry wizard below
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
// Suppresses source map uploading logs during build
silent: true,
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
},
{
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Transpiles SDK to be compatible with IE11 (increases bundle size)
transpileClientSDK: true,
// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
tunnelRoute: '/monitoring',
// Hides source maps from generated client bundles
hideSourceMaps: true,
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
}); |
Beta Was this translation helpful? Give feedback.
-
HI, I had same problem and just fix it reinstalling some npm packages. In my case I uninstall next14 and clerk (pnpm uninstall next @clerk/nextjs) and reinstall them (pnpm i next @clerk/nextjs). That did the trick for me. Hope it helps. |
Beta Was this translation helpful? Give feedback.
-
I'm having this same issue. (EDIT: using |
Beta Was this translation helpful? Give feedback.
-
I'm also having this issue and here's the minimal repo for reproducing the problem: https://github.com/mikeborozdin/next14-firebase-admin-issue Just run: npm i
npm run build All worked fine in Next 13 with the experimental server actions. |
Beta Was this translation helpful? Give feedback.
-
I faced the same issue and it seems like the problem is direct importing the server action in a I'm using firebase-admin to validate user in a server action: "use server";
import config from "@/config"
import admin from "firebase-admin";
import {initializeApp} from "firebase-admin/app";
import {getAuth} from "firebase-admin/auth";
export async myServerAction(payload) {
const app = initializeApp({
credential: admin.credential.cert({
projectId: config.project_id,
clientEmail: config.client_email,
privateKey: config.private_key,
}),
});
const firebaseAuth = getAuth(app);
// the rest of the logic
} Doesn't work: "use client";
import {myServerAction} from "@/server-actions"
export function MyForm() {
const handleSubmit=async()=>{
// handle loading state, etc...
const payload = {};
const response = await myServerAction(payload);
// handles response
}
return <form>
{/* input fields */}
<button type="button" onClick={()=>handleSubmit()}>Submit</button>
</form>
} I tried to pass the server action into client component via props (instead of directly importing it) and it worked. My solution: "use client";
export function MyForm({myServerAction}) {
const handleSubmit=async()=>{
// handle loading state, etc...
const payload = {};
const response = await myServerAction(payload);
// handles response
}
return <form>
{/* input fields */}
<button type="button" onClick={()=>handleSubmit()}>Submit</button>
</form>
} I'm not sure what I'm doing is correct, but it works for now. |
Beta Was this translation helpful? Give feedback.
-
Same problem here. Does anybody have a better solution than to go over every async function painstakingly?
|
Beta Was this translation helpful? Give feedback.
-
What?
…On Thu, 9 Nov 2023 at 23:20, Wojciech Bandzerewicz ***@***.***> wrote:
Same problem here. Does anybody have a better solution than to go over
every async function painstakingly?
—
Reply to this email directly, view it on GitHub
<#57535 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVPN23637VWDJTBWQCUTKLLYDVCJHAVCNFSM6AAAAAA6RZHXVGVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TKMRXGE3DE>
.
You are receiving this because you commented.Message ID: <vercel/next.
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I've run into this same issue with firebase-admin and have had to work around it a few times now. I also found moving the action to a nearby location can also seem to fix the webpack issue. Same directory, relative import seems fine
Different parent, path import is no bueno
Don't have time to really dig into the why here but it's another data point. |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, Been dealing with the same issue. I had this issue with I also made sure that my Do yourself a favour and try this before going to change all imports (as per the comment from @akwirick - value your development time!). |
Beta Was this translation helpful? Give feedback.
-
I solved this problem with For me, when server action includes When I removed it by replaced |
Beta Was this translation helpful? Give feedback.
-
As a workaround, dynamic import solved the issue in my case. "use server";
import { ... } from "firebase-admin/app";
export function doSomething() {
...
}; ↓ "use server";
export async function doSomething() {
const { ... } = await import("firebase-admin/app");
...
}; |
Beta Was this translation helpful? Give feedback.
-
I don't know if this will help, but in my case, I was able to Build by setting const path = require("path");
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
reactStrictMode: true,
experimental: {
outputFileTracingRoot: path.join(__dirname, "../../"),
esmExternals: false,
},
};
module.exports = nextConfig; |
Beta Was this translation helpful? Give feedback.
-
Hello my seniors, pls could anyone help me resolve this issue? I built a simple portfolio website and tried deploying on vercel but I had these logs :
|
Beta Was this translation helpful? Give feedback.
-
I digged a little bit and found that adding next.config.js file ->
|
Beta Was this translation helpful? Give feedback.
-
The solution to anyone coming across this later is that you are probably accidentally importing a server action in a client component. (Most likely you are incrementally switching to the app directory from the pages directory. For me this was caused by including a server action in my |
Beta Was this translation helpful? Give feedback.
-
I just uninstalled symbol-observable from webpack and all works fine now.
|
Beta Was this translation helpful? Give feedback.
-
If you have Dockerfile, the issue is this |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Seems like there is an issue with the latest version of Next.js. It fails to build with a webpack error.
Seems like this might be an issue with
firebase-admin
and Next.js working together.Here is the full error log:
Is there any way to fix this?
Beta Was this translation helpful? Give feedback.
All reactions