docusaurus: Fails when installing in a repo using Tailwind PostCSS plugin: cannot read config from undefined

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I’m using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

Cannot start/build docusaurus classic template

Tried with node@14/node@16/node@17

Steps to reproduce

Waiting for npx create-docusaurus@latest web classic to complete

cd web
yarn start

Expected behavior

Client compiled

Actual behavior

❯ yarn start
yarn run v1.22.17
$ docusaurus start
[INFO] Starting the development server...
[SUCCESS] Docusaurus website is running at http://localhost:3000/.

✖ Client
  Compiled with some errors in 3.01s
[...]
TypeError: Cannot read properties of undefined (reading 'config')
TypeError: Cannot read properties of undefined (reading 'config')
TypeError: Cannot read properties of undefined (reading 'config')
TypeError: Cannot read properties of undefined (reading 'config')
client (webpack 5.68.0) compiled with 88 errors

Your environment

new.docusaurus codesandbox bad gateway. new.docusaurus stackblitz all ok

  • Docusaurus version used: 2.0.0-beta.15
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Node.js 14/16/17
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): darwin 21 (arm64)

Reproducible demo

My project

  1. pnpm i to setup the project deps
  2. cd docs/web
  3. yarn
  4. yarn start
  5. See the errors in console without stack trace

You could remove the docs/web directory and create a docusaurus yourself

  1. rm -rf docs/web
  2. cd docs
  3. npx create-docusaurus@latest
  4. web for the project name
  5. classic for the template
  6. use typescript
  7. cd web
  8. yarn start
  9. See the errors in console without stack trace

Self-service

  • I’d be willing to fix this bug myself.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 42

Most upvoted comments

@Kiyozz I have concluded that it has nothing to do with PNPM, but rather about your PostCSS config. Because we use PostCSS, the loader will read the postcss.config.js file. However, this seems to be the cause: https://github.com/Kiyozz/papyrus-compiler-app/blob/139-docusaurus/postcss.config.js

I don’t have much experience with Tailwind CSS (I know @slorber does 😄) So I’d have to see where it goes wrong. I know this config is included in the Tailwind docs.

Edit. This seems to do the trick:

// postcss.config.js

module.exports = {
  plugins: {
    tailwindcss: {
      content: ["./src/**/*.{html,js}"],
    },
    autoprefixer: {},
  },
}

I wonder why the tailwind plugin is not reading the tailwind.config.js in this case

I don’t think anyone has stumbled upon it

During manual migration I faced the same issue. Not sure why. But when I removed all changes and tried migration for the second time I didn’t get the issue. Our repo doesn’t use tailwind css. I used yarn both time.

Adding a docs/web/postcss.config.js with module.exports = {} does seem to fix it. We probably won’t add it to the template, but I think it’s a good enough solution for your case.

I fixed it by creating tailwind.config.js file and adding basic default tailwind config 😄

module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
}

I’m having the same issue. The docusarus project works fines as an independent project. The moment I moves it to a subdir under another project with postcss.config.js in the parent dir, docusarus yarn build will fail.

root_project (next.js + tailwind)
   | package.json
   | postcss.config.js. <--- Test: rename this file and the error will go away
   ...
   | --- docs (docusaurus)
         ...

Workaround:

  • As suggested above, create tailwind.config.js in docs dir with the following content
module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
}

I hope this helps.

@slorber You need to have Tailwind installed and configured through postcss.config.js and/or tailwind.config.js in your parent directory.

It worked on my intel MacBook pro and throws config error in m1 mac 😅 .

I don’t think anyone has stumbled upon it (although I do know a few sites that use Tailwind + Docusaurus, or Docusaurus in a repo that also uses Tailwind) and it’s ultimately just a workaround. Preferably, we should be able to fix it, but given my limited knowledge in either PostCSS or Tailwind, I’ll let @slorber make the decision

It feels strange that postcss loader is searching recursively for a postcss config.

That’s typical behavior with most loaders. E.g. Babel loader will recursively look for a babel.config.js afaik.

Does having a postcss config in the template disallow the loader to search recursively?

Adding a docs/web/postcss.config.js with module.exports = {} does seem to fix it. We probably won’t add it to the template, but I think it’s a good enough solution for your case.

Yeah. Thank you @Josh-Cena. I think documenting and if possible, trying to catch the error and show some meaningful error messages would be wonderful.

I have an M1 pro and can’t reproduce this issue with those 3 commands 🤷‍♂️

Can reproduce on a fresh install on an M1 machine. The commands I ran was

npx create-docusaurus@latest docs classic
cd docs
yarn start

Fixed by following @harish-sethuraman 's advice, creating a tailwind.config.js with default configs in the root of docusaurus folder.

yarn version: 1.22.5 node version: v16.13.2

Meh, I’m M1 as well. Would be interesting to have any non-M1 contributor to investigate

@Kiyozz Do you use M1 mac by any chance?

Indeed