donnikitos / vite-plugin-php

Vite's speed and tooling to preprocess PHP-files!
https://www.npmjs.com/package/vite-plugin-php
MIT License
30 stars 0 forks source link

Import not working #7

Closed quantumcode-martin closed 1 month ago

quantumcode-martin commented 9 months ago

When I use import in a PHP script to import another PHP script it doesn't work locally (it works after building though).

I have index.php:

<?php
    include '/config.php';
    echo $test
?>

and config.php:

<?php
    define("test", "testing");
?>

vite.config.ts:

import usePHP from 'vite-plugin-php';

export default defineConfig({
  plugins: [usePHP({ binary: '/opt/homebrew/bin/php', entry: ['index.php', 'config.php', 'get-access/index.php'],})],
});

When opening the page I get this error:

Warning: include(/config.php): Failed to open stream: No such file or directory in /Users/martinhell/Documents/quantumcode/slaice-website/node_modules/vite-plugin-php/dist/router.php(14) : eval()'d code on line 17

Warning: include(): Failed opening '/config.php' for inclusion (include_path='.:/opt/homebrew/Cellar/php/8.2.12_1/share/php/pear') in /Users/martinhell/Documents/quantumcode/slaice-website/node_modules/vite-plugin-php/dist/router.php(14) : eval()'d code on line 17
donnikitos commented 9 months ago

This is how PHP works. It is trying to include config.php from the ROOT of your server. / is the root directory on a Linux system.

You should be able to include the file without the slash, or you can always use relative imports.

quantumcode-martin commented 9 months ago

Ok thanks.

This doesn't seem to work even if it works on production:

    <form class="flex center wrap" id="registrationForm" method="post" action="./register.php'?>">

The server is never returning a value it seems.

donnikitos commented 6 months ago

The most recent version of the plugin has a error catcher build in. Now you should be able to see the error causing the page to be blank.