dylanirlbeck / tailwind-ppx

A Reason/OCaml Pre-Processor eXtension (PPX) that validates your Tailwind classes at compile-time.
MIT License
152 stars 15 forks source link

"tailwind.css file not found in project hierarchy" error on fresh builds #119

Closed tsnobip closed 4 years ago

tsnobip commented 4 years ago

After cleaning up, my first build systematically fails with:

 tailwind.css file not found in project hierarchy. You may need to manually set the path to the file with the -path argument.

then it builds index.css and the following incremental builds work correctly. I also use a very simple monorepo setup with yarn, might be related.

My bsconfig.json is as follows:

{
  "name": "react-hooks-template",
  "reason": {
    "react-jsx": 3
  },
  "sources": [
    {
      "dir": "src",
      "subdirs": true,
      "generators": [
        {
          "name": "gen-tailwind",
          "edge": [
            "tailwind.css",
            ":",
            "index.css"
          ]
        }
      ]
    },
    {
      "dir": "__tests__",
      "type": "dev"
    },
    {
      "dir": "__stories__",
      "type": "dev",
      "generators": [
        {
          "name": "gen-tailwind",
          "edge": [
            "tailwind.css",
            ":",
            "../src/index.css"
          ]
        }
      ]
    }
  ],
  "package-specs": [
    {
      "module": "es6-global",
      "in-source": true
    }
  ],
  "suffix": ".bs.js",
  "namespace": true,
  "bs-dev-dependencies": [
    ...
  ],
  "bs-dependencies": [
    ...
  ],
  "generators": [
    {
      "name": "gen-tailwind",
      "command": "tailwindcss build $in -o $out -c ../../tailwind.config.js"
    }
  ],
  "ppx-flags": [
    "bs-log/ppx",
    "reason-relay/ppx",
    [
      "@dylanirlbeck/tailwind-ppx/tailwind-ppx",
      "-path src/tailwind.css"
    ]
  ],
  "warnings": {
    "warning": "+10",
    "error": "+A"
  },
  "refmt": 3
}

Any idea why this happens?

dylanirlbeck commented 4 years ago

@tsnobip Just because I'm curious -- can you try removing the generator config and see what happens? I feel like I came across this a long time ago..

tsnobip commented 4 years ago

Oh interesting, I'll check it out and let you know :)

tsnobip commented 4 years ago

no @dylanirlbeck, unfortunately I get the same error when I remove the generators 😞

tsnobip commented 4 years ago

@dylanirlbeck I looked for a minimal repro and actually just cloning https://github.com/dylanirlbeck/my-first-pr/ and doing bsb -clean-world will reproduce the same error at next build since it erases tailwind.css. So definitely not related to monorepo.

dylanirlbeck commented 4 years ago

@tsnobip So I think this behavior is in fact due to how BuckleScript generators work, and thus is not a bug with tailwind-ppx (I may still be wrong, but this is my guess). In short, the generator automatically deletes the $out file when you run bsb -clean-world, and in this case that $out file is tailwind.css.

I can try and improve the docs and/or investigate the process to see if tailwind-ppx can consume tailwind.css in a smarter way with the generator in mind, but for now I'm going to close this issue since I don't think it's related to tailwind-ppx.

That said, I'm happy to re-open at any time if this turns out to be a tailwind-ppx issue.

tsnobip commented 4 years ago

oh OK @dylanirlbeck, I'm not really sure how to make it work without the generator though, you do need a tailwind.css to be generated somehow and it shouldn't be versioned, so what's the regular process?

dylanirlbeck commented 4 years ago

@tsnobip The generator is just an automated way to run the Tailwind CLI!

If the generator was working properly, you should already have the tailwind-css NPM package installed in your project. Thus, all you need to do is to manually generated the tailwind.css file whenever you change index.css, which can be done with something that looks like the following command (this is pulled right from the generator docs):

tailwindcss build index.css -o tailwind.css -c ../../tailwind.config.js

You might need an npx tailwindcss ..., but hopefully the package gets put in your PATH by default.

Let me know if you have any other questions!

tsnobip commented 4 years ago

works perfectly thank you, I feel a bit dumb now ^^ Maybe the use of generators should document this caveat though, when I have some time I'll try to see if the generator can be triggered before the build so it doesn't create this situation anymore.

dylanirlbeck commented 4 years ago

Awesome! Yeah if you have any insights please let me know, I'd love to change our docs if there is a better way to do this.