Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 276
mukunda Avatar asked Mar 07 '26 06:03

mukunda


2 Answers

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.

like image 125
mukunda Avatar answered Mar 09 '26 18:03

mukunda


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.

like image 35
Mauricio Gómez Avatar answered Mar 09 '26 19:03

Mauricio Gómez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!