fix: Ensure Windows path compatibility in web platform transformation#860
fix: Ensure Windows path compatibility in web platform transformation#860dmitryshostak wants to merge 1 commit intonativewind:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@marklawlor We encountered the same issue on Windows as well, and the fix appears to be working as expected. 🙏 |
|
Same here. It would be great if it could be merged soon. By the way, great work by @marklawlor and all contributors, Nativewind is amazing |
|
@dmitryshostak how can i use this branch in my project now? I am blocked. |
|
Hi, @aaronksaunders. I think there are ways to install a dependency from a pull request / fork, but at least it didn't seem to work for me. I created this simple PHP script that applies the fix once the nativewind package has been installed. I run it whenever I install my front-end dependencies. You can easily translate the script to whatever language you prefer. <?php
$filePath = 'front-end/node_modules/nativewind/dist/metro/transformer.js';
$content = file_get_contents($filePath);
$issue = '`require(\'${config.nativewind.output}\');`';
if (! str_contains($content, $issue)) {
echo 'NativeWind fix already applied!';
return;
}
$fix = '`require(\'${config.nativewind.output.replace(/\\\\/g, \'\\\\\\\\\')}\');`';
$result = str_replace($issue, $fix, $content);
file_put_contents($filePath, $result);
echo 'NativeWind fix applied successfully!'; |
|
Inspired by @Alejandro-M-Cruz, I've created JavaScript instead. You can place it in the root directory of your project. To integrate this script with your application, add the following entry to your package.json. This will ensure the script runs every time you start your program: Here is the JavaScript script: This setup allows the fix.js script to batch process necessary adjustments automatically whenever you initiate your project with expo start. |
|
@rickychan0611 great! the only thing - I would add it to |
|
The script by @rickychan0611 works but in my end first install and run of the web script will cause the following error: However, if I stop the server and run the web script again, it now works as normal. Anyone know why? |
You need to clear the cache when starting the server |
|
As native-wind is no longer maintained, I have switched to tailwind-react-native-classnames. It is also much faster |
for real? the guy announced it or just stopped merging PRs? |
|
@rickychan0611 it's not no-longer maintained, check this: #600 |
|
@marklawlor please merge this 💔 |
|
@guibzo nice patch! Have you ever used pnpm patch before? It does something like this. |
I did not, but probably it would work as well as with postinstall. |
|
please merge this |
|
i tried this patch but it didn't work for me while using flatlist component |
|
We create this patch using patch-package. create: diff --git a/node_modules/nativewind/dist/metro/transformer.js b/node_modules/nativewind/dist/metro/transformer.js
index 75f0c40..9b6d303 100644
--- a/node_modules/nativewind/dist/metro/transformer.js
+++ b/node_modules/nativewind/dist/metro/transformer.js
@@ -11,7 +11,8 @@ const transformer_1 = require("react-native-css-interop/metro/transformer");
async function transform(config, projectRoot, filename, data, options) {
if (path_1.default.resolve(process.cwd(), filename) === config.nativewind.input) {
if (options.platform === "web") {
- return metro_transform_worker_1.default.transform(config, projectRoot, filename, Buffer.from(`require('${config.nativewind.output}');`, "utf8"), options);
+ const windowsCompatibleOutputPath = config.nativewind.output.replace(/\\/g, '\\\\');
+ return metro_transform_worker_1.default.transform(config, projectRoot, filename, Buffer.from(`require('${windowsCompatibleOutputPath}');`, "utf8"), options);
}
else {
const css = config.nativewind.css[options.platform ?? "native"] ??
then add to {
"scripts": {
// ... your scripts
"postinstall": "patch-package"
}
// ... rest of package.json properties
} |
|
This is how it worked for me Using Yarnyarn add postcss postcss-cli tailwindcss autoprefixer cssnano --dev Using npmnpm install postcss postcss-cli tailwindcss autoprefixer cssnano --save-dev 2: Create a file named postcss.config.js in the root of your project with the following content: module.exports = { Step 3: Create a script to build your CSS. In your package.json, add a script to run PostCSS: "scripts": { yarn build:css will find new file created called: will use it in metro config const { getDefaultConfig } = require('expo/metro-config'); const config = getDefaultConfig(__dirname); module.exports = withNativeWind(config, { input: './build.css' }); |
|
This file seems to no longer exist, I'll check on this with Mark |

This PR fixes an issue where Windows paths were not correctly handled in the Metro transformer's web platform transformation, causing incorrect runtime module resolution.
It's a duplicate of #854, but with a better naming so we don't break it again. ❗
@marklawlor could you please merge it ASAP as we're using
nativewindin production and we hate to patch it :)The related issue - #784 (comment)