13

I'm using Vue 3 and trying to add tailwindcss into it from the following tutorial. https://tailwindcss.com/docs/guides/vue-3-vite#install-tailwind-via-npm

I have installed the dependencies using the following command,

npm install -D tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9

But when I tried to create the configuration files using the following command

npx tailwindcss init -p

It is giving me the following error.

npx: installed 83 in 5.2s Cannot find module 'autoprefixer' Require stack:

  • /~/.npm/_npx/33283/lib/node_modules/tailwindcss/lib/cli/commands/build.js
  • /~/.npm/_npx/33283/lib/node_modules/tailwindcss/lib/cli/commands/index.js
  • /~/.npm/_npx/33283/lib/node_modules/tailwindcss/lib/cli/main.js
  • /~/.npm/_npx/33283/lib/node_modules/tailwindcss/lib/cli.js

I don't know why autoprefixer is not detecting because I have already installed it. Even the package.json have it.

{
  "name": "wooclime",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^3.0.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0",
    "autoprefixer": "^9.8.6",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^7.0.0-0",
    "postcss": "^7.0.35",
    "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.2"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/vue3-essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}
5
  • try it out without flag npx tailwindcss init Commented Dec 11, 2020 at 22:29
  • @BoussadjraBrahim still same, what does that flag means? Commented Dec 11, 2020 at 22:30
  • I don't know the meaning of -p flag Commented Dec 11, 2020 at 22:32
  • @BoussadjraBrahim ok, but still same error, don't know why it is happening. I think if I install the autoprefixer in the dependencies, instead of devDevependencies it will solve the issue. Commented Dec 11, 2020 at 22:33
  • Please solve it in the answer section, it easy to see. Anw upgrade node version work for me Commented May 15, 2021 at 2:57

4 Answers 4

47

Run:

npx tailwindcss-cli@latest init -p
Sign up to request clarification or add additional context in comments.

Comments

3

Please uninstall run this command:

npm uninstall tailwindcss postcss autoprefixer

After this module is uninstall, please run this command:

npm install tailwindcss@latest postcss@latest autoprefixer@latest

Comments

1

You could use the following command using the tailwindcss cli with latest version an the flag --postcss or -p

npx tailwindcss-cli@latest init --postcss

Or follow these steps :

After installing that dependencies try to create the following files project root without running that command :

tailwind.config.js

module.exports = {
    purge: [],
    darkMode: false, // or 'media' or 'class'
    theme: {
        extend: {},
    },
    variants: {
        extend: {},
    },
    plugins: [],
};

postcss.config.js

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}

Then in your main CSS file add :

@tailwind base;
@tailwind components;
@tailwind utilities;

1 Comment

I found an suggestion about updating the nodejs from this link. github.com/tailwindlabs/tailwindcss/issues/2831 I'm trying to update and let see if it solve the issue
0

I had same issue

I downgrade the tailwindcss package to 1.0.5 from latest

Now it is working

Comments

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.