Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure Windows path compatibility in web platform transformation #860

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dmitryshostak
Copy link

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 nativewind in production and we hate to patch it :)

The related issue - #784 (comment)

Copy link

vercel bot commented Mar 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nativewind ✅ Ready (Inspect) Visit Preview Mar 29, 2024 8:05pm

@yjose
Copy link
Contributor

yjose commented Mar 31, 2024

@marklawlor We encountered the same issue on Windows as well, and the fix appears to be working as expected. 🙏

@Alejandro-M-Cruz
Copy link

Alejandro-M-Cruz commented Apr 22, 2024

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

@aaronksaunders
Copy link

@dmitryshostak how can i use this branch in my project now? I am blocked.

@Alejandro-M-Cruz
Copy link

Alejandro-M-Cruz commented Apr 27, 2024

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!';

@rickychan0611
Copy link

rickychan0611 commented Apr 28, 2024

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:

 "scripts": {
    "start": "node fix.js && expo start"
  },

Here is the JavaScript script:

// fix.js
const fs = require('fs');
const path = require('path');

const filePath = path.join('.', 'node_modules', 'nativewind', 'dist', 'metro', 'transformer.js');

fs.readFile(filePath, 'utf8', (err, content) => {
    if (err) {
        console.error(err);
        return;
    }

    const issue = '`require(\'${config.nativewind.output}\');`';

    if (!content.includes(issue)) {
        console.log('NativeWind fix already applied!');
        return;
    }

    const fix = '`require(\'${config.nativewind.output.replace(/\\\\/g, \'\\\\\\\\\')}\');`';
    const result = content.replace(issue, fix);

    fs.writeFile(filePath, result, 'utf8', (err) => {
        if (err) {
            console.error(err);
            return;
        }
        console.log('NativeWind fix applied successfully!');
    });
});

This setup allows the fix.js script to batch process necessary adjustments automatically whenever you initiate your project with expo start.

@dmitryshostak
Copy link
Author

@rickychan0611 great! the only thing - I would add it to postinstall :) 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants