Next JS application deployment issues: npx next build -> Error: Cannot find module '@tailwindcss/postcss'
apotapov
PROOP

a year 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. (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 ()

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

Solved$10 Bounty

Pinned Solution

apotapov
PROOP

a year 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

Railway
BOT

a year ago


fra
HOBBY

a year ago

did you try deleting packages-lock.json & reinstall?


a year 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?

apotapov
PROOP

a year ago

reinstall generates an identical package-lock.json


vivekvt

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", } ```

apotapov
PROOP

a year ago

sh: 1: next: not found


a year 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**](https://docs.railway.com/guides/cli). **3** Deploying from a **Docker Image**.

apotapov
PROOP

a year ago

Deploying from CLI: railway up


a year ago

if you don't mind, can you share full package.json file


apotapov
PROOP

a year 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

apotapov
PROOP

a year 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 11 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...