7 months ago
I've been banging my head against the wall. The build step fails for me for a NextJS app. This has worked fine locally and on Heroku, and I've been able to deploy at least once before, but in the last few hours I keep hitting the same build error.
Here's the relevant part of my package.json:
"scripts": {
"postinstall": "npx prisma generate",
"build": "npx next build && npx prisma migrate deploy",
"start": "npx next start","dependencies": {
"next": "^15.2.0",
...
"@tailwindcss/postcss": "^4.1.11",
...
"tailwindcss": "^4.1.11",
"tailwind-merge": "^3.3.1",
"tailwindcss-animate": "^1.0.7",
...
},Here is the error stack trace:
Failed to compile.
app/(marketing)/layout.tsx
An error occurred in next/font.
Error: Cannot find module '@tailwindcss/postcss'
Require stack:
- /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js
- /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/webpack/config/blocks/css/index.js
- /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/webpack/config/index.js
- /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/webpack-config.js
- /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/webpack/plugins/next-trace-entrypoints-plugin.js
- /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/collect-build-traces.js
- /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/index.js
- /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/cli/next-build.js
at Function.<anonymous> (node:internal/modules/cjs/loader:1249:15)
at /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/server/require-hook.js:57:36
at Function.resolve (node:internal/modules/helpers:151:19)
at loadPlugin (/root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:53:32)
at /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:185:56
at Array.map (<anonymous>)
at getPostCssPlugins (/root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:185:47)
at async /root/.npm/_npx/8b377f6eec906bc4/node_modules/next/dist/build/webpack/config/blocks/css/index.js:125:36
app/(marketing)/layout.tsx
Pinned Solution
7 months ago
Unbelievable. Found the issue. I had the following line in my package.json after removing it everything worked...cacheDirectories": [
"node_modules/"
]
Thanks for the prompt!
10 Replies
7 months ago
Hey there! We've found the following might help you get unblocked faster:
🧵 TypeScript Module Resolution Issues - Cannot Find Controller Files in Build Environment
🧵 "Persistent 'Cannot find module 'dotenv/config'' Error Despite Correct Dockerfile Configuration
🧵 Backend Deployment Issue - "Error: Cannot find module '/app/dist/main.js'"
If you find the answer from one of these, please let us know by solving the thread!
7 months ago
did you try deleting packages-lock.json & reinstall?
7 months ago
Try removing npx from next command
just keep "next build" , "next start"
"scripts": {
"postinstall": "npx prisma generate",
"build": "next build && npx prisma migrate deploy",
"start": "next start",
}fra
did you try deleting packages-lock.json & reinstall?
7 months ago
reinstall generates an identical package-lock.json
vivekvt
Try removing npx from next commandjust keep "next build" , "next start""scripts": { "postinstall": "npx prisma generate", "build": "next build && npx prisma migrate deploy", "start": "next start", }
7 months ago
sh: 1: next: not found
7 months ago
how are you trying deploying your nextjs app to railway?
1 Deploying from GitHub.
2 Deploying with the CLI.
3 Deploying from a Docker Image.
vivekvt
how are you trying deploying your nextjs app to railway?1 Deploying from GitHub.2 Deploying with the CLI.3 Deploying from a Docker Image.
7 months ago
Deploying from CLI: railway up
7 months ago
So the funny thing is I have deployed successfully once already. So I tried recreating that. I ssh'ed into service with railway ssh copied the contents of package.json replaced the one I had locally and ran npm install to rebuild package-lock.json , then deployed with railway up and got the exact same error.
I'm not sure if it's some weird caching issue with the build process or what. I've even tried to set up a railway.json file. Intrestingly it does recognize the file, because it blocked me from changing the build or start command in the UI after I added it, but it doesn't use the custom npm ci --verbose command I specified. in the file.
vivekvt
if you don't mind, can you share full package.json file
7 months ago
Unbelievable. Found the issue. I had the following line in my package.json after removing it everything worked...cacheDirectories": [
"node_modules/"
]
Thanks for the prompt!
Status changed to Solved jake • 7 months ago
