13

I'm following the documentation, however when use:

npx tailwindcss init

Not working:

Error: Cannot find module 'C:\path\to\project\tailwindcss\lib\cli.js'

5
  • 1
    Is your practice tailwind directory initialized as node project? Commented Dec 28, 2021 at 12:28
  • @Soyokaze yes it is Commented Dec 29, 2021 at 14:20
  • 1
    I dont know why but changing the directory worked. Commented Dec 29, 2021 at 15:50
  • yeah cuz some commands run on the basis of current directory Commented Dec 29, 2021 at 18:53
  • 1
    Since January 2025, this a relevant answer for v4: Problem installing TailwindCSS with Vite, after "npx tailwindcss init -p" command Commented Mar 31 at 8:55

8 Answers 8

38

Step : 1 Correct you directory path like this C:\Users\user\Documents\Web Dev\Tailwindcss_AlpineJs\pratice tailwind then try this command npx tailwindcss init

Step : 2 Not working above step : 1 then try this command : npx tailwindcss-cli@latest init -p.

Sign up to request clarification or add additional context in comments.

3 Comments

i am having the same issue in tailwind 4
@kode for TailwindCSS v4 just follow a newer answer: stackoverflow.com/a/79545848/15167500
npx tailwindcss-cli@latest init -p - works for me, Thanks
18

The latest version Tailwindcss@4 does not support -> npx tailwindcss init

Installation Using PostCSS

I installed the Tailwindcss@3 version , the command is running fine . Steps :-

npm init -y 
npm install -D tailwindcss@3 @tailwindcss/postcss postcss
npx tailwindcss init -p

Comments

11

I know the question was based on TailwindCSS v3, but newcomers will increasingly use v4, so I'll provide a v4-related answer.

Starting from January 2025, with the release of TailwindCSS v4, running npm install tailwindcss will install the new v4 instead of v3. This is important because v4 comes with several breaking changes.

v4 related similar question:

TailwindCSS v3

If you still want to use v3, install it with a specific version:

npm install tailwindcss@3

TailwindCSS v4

If you're looking for breaking changes in v4 (why not working npx tailwindcss init), here's a quick summary:

  • CSS-first configuration replaces tailwind.config.js.
  • The init process has been removed since it's no longer needed.
  • The CLI and PostCSS packages have been separated, so to use npx tailwindcss, you now need the @tailwindcss/cli package, and the new command is: npx @tailwindcss/cli. But for usage with PostCSS or Vite, no CLI command is needed anymore.

See more:

Comments

4
  1. Check if your directory is initialized as a node project, i.e. it contains package.json file. If not then do this:
$/> npm init -y
  1. Install tailwindcss as a dev dependency (optional as a dev dependency)
$/> npm i -D tailwindcss

3 Comments

Yeah i already did that.
I am setting up a Laravel package with tailwindcss and couldn't figure out why I was getting a 'command not found: tailwindcss' when trying to initialize tailwindcss. Needed to initialize and get a package.json file created. Thanks!
@mmv_sat From January 2025, you install v4 by default in TailwindCSS, and Laravel has supported this since v12. Simply put, the explanation is just the removal of the init process, because JS-based configuration is no longer needed. See: Problem installing TailwindCSS after npx tailwindcss init command - tailwindcss not recognized - NPM error could not determine executable to run and maybe related for you: What's breaking changes from v4?
2

i was facing the same issue installing tailwindcss and postcss with vite but i was able to fix this issue by adding the tailwind.config.ts file manually and filling in the required information then i added the tailwindcli in my project with the command given above

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
1

I encountered the same issue with the Nuxt Tailwind CSS module. It occurred because I had been using pnpm as the package manager. Switching to npm resolved the error. Additionally, manually installing the Tailwind CSS package and setting it up should prevent similar errors from occurring.

Comments

0

I had the same problem in my case, the parent folder had &, something like "Html&Css" and even if there was another folder here, the error was resolved after I removed the & from the parent folder.

So, the error was solved after I eliminated the "&"

I hope it helps someone. And it took me a while to find what the problem was

1 Comment

From January 2025, you install v4 by default in TailwindCSS. Simply put, the explanation is just the removal of the init process, because JS-based configuration is no longer needed. See: Problem installing TailwindCSS after npx tailwindcss init command - tailwindcss not recognized - NPM error could not determine executable to run and maybe related for you: What's breaking changes from v4?
0

you should to install v3
command:
npm install -D tailwindcss@3 postcss autoprefixer
then:
npx tailwindcss init -p

3 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
From January 2025, you install v4 by default in TailwindCSS. Simply put, the explanation is just the removal of the init process, because JS-based configuration is no longer needed. See: Problem installing TailwindCSS after npx tailwindcss init command - tailwindcss not recognized - NPM error could not determine executable to run and maybe related for you: What's breaking changes from v4?
Recommending the installation of a version that is no longer actively maintained has never been worthwhile or useful. Especially without an explanation, your answer is misleading, and I do not recommend using it. Use v4: stackoverflow.com/a/79545848/15167500

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.