File size: 2,222 Bytes
e1f81b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@echo off

REM Fix React Native library symlinks for Windows users

REM This script creates symlinks to avoid node command execution during Android builds

REM Automatically runs after npm install via postinstall script

setlocal enabledelayedexpansion



REM Check if node_modules exists
if not exist "node_modules" (
    echo πŸ’‘ No node_modules directory found, skipping symlink creation
    exit /b 0
)

echo πŸ”§ Creating React Native symlinks to avoid node command execution...



REM Change to script directory
cd /d "%~dp0"



REM Counter for created symlinks
set count=0



REM Create symlinks for all react-native-* libraries
for /d %%d in (node_modules\react-native-*) do (

    REM Check if the directory exists and create node_modules subfolder if needed
    if exist "%%d" (
        if not exist "%%d\node_modules" (
            mkdir "%%d\node_modules" 2>nul
        )



        REM Check if symlink doesn't already exist
        if not exist "%%d\node_modules\react-native" (

            REM Create symbolic link (requires admin privileges or developer mode)
            mklink /D "%%d\node_modules\react-native" "..\..\react-native" >nul 2>&1
            if !errorlevel! equ 0 (
                echo   βœ… Created symlink for %%d
                set /a count+=1
            ) else (

                REM Fallback: try junction if mklink fails
                mklink /J "%%d\node_modules\react-native" "..\..\react-native" >nul 2>&1
                if !errorlevel! equ 0 (
                    echo   βœ… Created junction for %%d
                    set /a count+=1
                ) else (
                    echo   ❌ Failed to create symlink/junction for %%d
                    echo      πŸ’‘ Try running as administrator or enabling Developer Mode
                )
            )
        )
    )
)

if !count! equ 0 (
    echo πŸ’‘ All React Native symlinks already exist or none were needed
) else (
    echo πŸŽ‰ Created !count! React Native symlinks successfully!
)

echo πŸ’‘ This fixes the 'command node not found' error during Android builds.
echo πŸ’‘ If symlinks failed, try running as administrator or enabling Windows Developer Mode.

endlocal