docusaurus: Fails when installing in a repo using Tailwind PostCSS plugin: cannot read config from undefined
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I’m using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand 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
pnpm ito setup the project depscd docs/webyarnyarn start- See the errors in console without stack trace
You could remove the docs/web directory and create a docusaurus yourself
rm -rf docs/webcd docsnpx create-docusaurus@latestwebfor the project nameclassicfor the templateuse typescriptcd webyarn start- 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
@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.jsfile. However, this seems to be the cause: https://github.com/Kiyozz/papyrus-compiler-app/blob/139-docusaurus/postcss.config.jsI 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:
I wonder why the tailwind plugin is not reading the
tailwind.config.jsin this caseDuring 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.
I fixed it by creating
tailwind.config.jsfile and adding basic default tailwind config 😄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.jsin the parent dir, docusarusyarn buildwill fail.Workaround:
tailwind.config.jsin docs dir with the following contentI hope this helps.
@slorber You need to have Tailwind installed and configured through
postcss.config.jsand/ortailwind.config.jsin your parent directory.It worked on my intel MacBook pro and throws
configerror 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
That’s typical behavior with most loaders. E.g. Babel loader will recursively look for a
babel.config.jsafaik.Adding a
docs/web/postcss.config.jswithmodule.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
Fixed by following @harish-sethuraman 's advice, creating a
tailwind.config.jswith 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
Indeed