Hello! My first post although I’ve lurked for a while. I’m picking up a Redwood side project again after a couple of months and am running into a couple of fairly opaque issues that I’m wondering if anyone has any advice on.
I’m using twin.macro for styling, which (before v0.35) has worked a treat up until I try to add a prerender prop to one of my routes. Twin is a Babel macro which allows for writing Tailwind classes within (in my case) styled-components. I’ll separate out the two issues below:
with Redwood 0.35
As soon as I import tw from 'twin.macro'
, the dev process can suddenly no longer render the page, failing with the error:
Failed to compile.
../node_modules/babel-plugin-macros/node_modules/cosmiconfig/dist/readFile.js
Module not found: Error: Can't resolve 'fs' in '/Users/me/sandbox/rw-twin/node_modules/babel-plugin-macros/node_modules/cosmiconfig/dist'
This works absolutely fine in Redwood 0.34, so I was suspecting some sort of version mismatch nested in the dependency tree. I tried pinning cosmiconfig to 6.0.0 via the resolutions
field in package.json, but to no avail (this was a bit of a shot in the dark anyway).
This is the bigger of my two issues as without a solution, the only workaround I can see would be to stop using twin.macro and rewrite all of my existing styles!
with Redwood 0.34
Back on 0.34, running yarn rw dev
or yarn rw build
both presented no problems until I added the prerender
prop to one of my routes. The build command then failed with an error from twin.macro noting that it couldn’t find one of the custom styles from my Tailwind config:
---------- Error rendering path "/" ----------
MacroError: /Users/me/sandbox/rw-twin/web/src/pages/HomePage/HomePage.js:
✕ text-customColor was not found
Try one of these classes:
[there follows a long list of similar inbuilt class names, omitted for brevity]
Note that this is thrown in the ‘prerender’ phase of the process - the ‘build’ phase completes successfully.
Interestingly, no such error is thrown if I simply don’t reference any of my custom styles. Using only Tailwind’s predefined styles allows the build and the prerender to complete successfully.
Reproduction
It’s entirely possible that whatever’s causing the issues is something needing fixed on twin’s side, but I thought I’d post here first to see if anyone had any experience with this sort of problem, or could even help me narrow down what to put in a bug report. I’m certainly no expert on configuring Babel and other aspects of the build process (which is one of the things I appreciate Redwood taking care of!) but in this case that does seem to be where the problem lies.
I’ve created a Git repository with a minimal reproduction of the issue, currently using Redwood 0.35. I can push up a version with 0.34 too if that becomes useful.
Any thoughts would be very much appreciated!