Skip to content

Fusion has trouble working on Windows #17

@johnRivs

Description

@johnRivs

I came across the same issue someone had when trying to install FusionCasts.

Error retrieving config: spawnSync php ENOENT

Reason

On Windows, Herd creates a .bat file that points to the selected PHP executable.

> where php
C:\Users\John\.config\herd\bin\php.bat

> cat C:\Users\John\.config\herd\bin\php.bat
@echo off
"C:\Users\John\.config\herd\bin\php83\php.exe" %*

This seems to prevent Node from spawning a PHP process.

Workaround

I added some code to find the actual PHP executable in packages\vue\vite.js and packages\vue\Transformer.js.

function findPhpExecutableOnWindows() {
  try {
    let whereResult = spawnSync('where', ['php'], { encoding: 'utf8' });

    if (whereResult.error || whereResult.status !== 0) {
      console.error('Could not find PHP using where command:', whereResult.error || whereResult.stderr);

      return null;
    }

    let phpPath = whereResult.stdout.split('\n')[0].trim();

    if (phpPath.toLowerCase().endsWith('.bat')) {
      let batContent = fs.readFileSync(phpPath, 'utf8'),
          phpExeMatch = batContent.match(/"([^"]+\\php(?:\d+)?\\php\.exe)"/);

      if (phpExeMatch && phpExeMatch[1]) {
        return phpExeMatch[1];
      } else {
        console.error('Could not extract PHP executable path from batch file');

        return null;
      }
    } else {
      return phpPath;
    }
  } catch (error) {
    console.error('Error finding PHP executable:', error);

    return null;
  }
}

function getPhpExecutable() {
  if (os.platform() === 'win32') {
    return findPhpExecutableOnWindows() || 'php';
  } else {
    return 'php';
  }
}

Why not a PR?

My workaround is:

  • Way too hacky.
  • Very specific (Herd)
  • I don't know where else this would be needed.

Also, I couldn't get Fusion to work in the end. Once I visited /, this is what I got in the console.

9:49:41 PM [vite] [fusion] Conformed \storage\fusion\PHP\PagesIndexGenerated.php
9:49:42 PM [vite] [fusion] PHP process exited with code: 1
9:49:42 PM [vite] [fusion] PHP stdErr output:
9:49:42 PM [vite] [fusion] PHP stdOut output:
   Illuminate\Database\Eloquent\ModelNotFoundException

  No query results for model [Fusion\Models\Component].

  at vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:665
    661▕         if (! is_null($model = $this->first($columns))) {
    662▕             return $model;
    663▕         }
    664▕
  ➜ 665▕         throw (new ModelNotFoundException)->setModel(get_class($this->model));
    666▕     }
    667▕
    668▕     /**
    669▕      * Execute the query and get the first result or call a callback.

  1   vendor\fusionphp\fusion\src\Console\Commands\Shim.php:29
      Illuminate\Database\Eloquent\Builder::firstOrFail()

  2   vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36
      Fusion\Console\Commands\Shim::handle()


9:49:42 PM [vite] Internal server error:
  Plugin: fusion-vue
  File: F:/www/fusion/resources/js/Pages/Index.vue
      at ChildProcess.<anonymous> (file:///F:/www/fusion/vendor/fusionphp/fusion/packages/vue/Transformer.js:298:25)
      at ChildProcess.emit (node:events:524:28)
      at maybeClose (node:internal/child_process:1101:16)
      at Socket.<anonymous> (node:internal/child_process:456:11)
      at Socket.emit (node:events:524:28)
      at Pipe.<anonymous> (node:net:351:12)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions