Error: Cannot find module 'tailwindcss' (Next.js application)
Asked Answered
O

6

6

I recently updated my Node Package Manager in accordance with this post. However, now when I create a new Next.js app and run it using npm run dev, I get the following error:

error - ./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[2].oneOf[8].use[1]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[2].oneOf[8].use[2]!./styles/globals.css
Error: Cannot find module 'tailwindcss'
Require stack:
- E:\Code\testing\node_modules\next\dist\build\webpack\config\blocks\css\plugins.js
- E:\Code\testing\node_modules\next\dist\build\webpack\config\blocks\css\index.js
- E:\Code\testing\node_modules\next\dist\build\webpack\config\index.js
- E:\Code\testing\node_modules\next\dist\build\webpack-config.js
- E:\Code\testing\node_modules\next\dist\server\dev\hot-reloader.js
- E:\Code\testing\node_modules\next\dist\server\dev\next-dev-server.js
- E:\Code\testing\node_modules\next\dist\server\next.js
- E:\Code\testing\node_modules\next\dist\server\lib\start-server.js
- E:\Code\testing\node_modules\next\dist\cli\next-dev.js
- E:\Code\testing\node_modules\next\dist\bin\next
    at Array.map (<anonymous>)

What is causing the error and how do I fix it ? I don't want to build my project using TailwindCSS and hence, do not want to install it.

Edit: I had run the npm install -D tailwindcss@latest postcss@latest autoprefixer@latest command previously to fix the error. It didn't help. I tried uninstalling it and that didn't help either.

Onshore answered 27/7, 2022 at 18:31 Comment(1)
Have you tried that? 'npm uninstall tailwindcss' and then 'rm -rf node_modules package-lock.json' and then 'npm install'.Snaggletooth
O
6

This post fixed my error. I had a postcss.config.js file in the parent directory that I hadn't noticed. All my Next.js projects were created in a sub-directory and hence, the oversight.

Onshore answered 28/7, 2022 at 10:38 Comment(0)
M
6

In my case, I was build a multi stage Docker build which had tailwindcss as a devDependecy in the package builder step. The packages were being installed using yarn wokspaces focus --all --production. As the second stage was being build, tailwindcss was missing since as a devDependency and it wasn't being installed and this error did pop up.

Materialism answered 12/7, 2023 at 6:40 Comment(1)
So what's the solution? your answer could add actionable steps to fix the issueProt
S
1

In my case, this issue occurred during production build. By default NPM production mode won't install devDependancies. I had to use the flag --include=dev when running npm install

npm install --include=dev
Sculpin answered 21/8 at 12:53 Comment(0)
T
0

Remove the node_modules and .next folders and follow the guide here: https://tailwindcss.com/docs/guides/nextjs

Tessy answered 27/7, 2022 at 19:1 Comment(1)
It didn't help. Actually, I don't want to use TailwindCSS in my project at all. I ran my server without modifying the default Next.js installation and the error showed up.Onshore
A
0

install below command

npm install -D tailwindcss postcss autoprefixer

and After install restart the server

Aikoail answered 28/3, 2023 at 11:15 Comment(0)
Y
-1

in my own case, i install sudo npm install tailwindcss-animate class-variance-authority clsx tailwind-merge lucide-react

Yaya answered 4/12, 2023 at 21:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.