kirby-vite
kirby-vite copied to clipboard
Error in production, but not in local
When I try to publish my site in production, I get this error:
str_starts_with(): Argument #1 ($haystack) must be of type string, bool given
from this file, line 51:
/site/plugins/kirby-vite/packages/kirby-vite/Vite.php
if (str_starts_with($fullPath, $rootPath)) {
return ltrim(substr($fullPath, strlen($rootPath)), DIRECTORY_SEPARATOR);
}
Any idea what it could be?
Can you share your setup with a minimal repository? There used to be a similar issue but I forgot what caused it 🙈
Ah I found it: maybe issue #40 can help you
Thanks for taking a look. I realised the website is looking for /site/config/vite.config.php
but that file is in the .gitignore
. And the error I posted above is caused when I stop ignoring that file and pushing it to the server. I also realised I can't use Node on my remote server, so no npm install
available there. I guess that's the problem? If so, any idea how to bypass it?
The file is git ignored on purpose, because it is auto-generated by the kirby-vite plugin. I don't like to commit any files that are auto-generated or installed, like /node_modules
and composer's /vendor
because you can re-create these files any time, so there is no need for them to end up in git. But of course you have to upload these files to your server.
I don't know how you deploy, but if you use git, you have to run npm install
, npm run build
and composer install
on the server. If you can't use node then yes, you have to remove the auto-generated files from .gitignore
. For simple websites I also use a cheap shared hosting webspace without node and to deploy these website I use rsync
or lftp
. This way I can still ignore all auto-generated files from git, but I upload them to the server never the less. I also made a simple tool to help with lftp
: very-simple-deploy, I you have ssh access you could also use rploy. Here is an example setup of how I use my lftp tool with Kirby and Vite :)
If you wan't to use git, it would be enough the un-ignore everything composer-related (/vendor
, /kirby
, /site/plugins
), the /site/config/vite.config.php
and the outDir from vite (/dist
, or /public/dist
depending on your setup). You don't have to un-ignore /node_modules
because they are bundled away with Vite.
amazing, many thanks for your reply!
Glad I could help :) I'll close this issue, but add another one as a reminder to add a better error message, something like vite.config.php not found
instead of the cryptic error you got!
Fantastic, thank you for your work! For the record, I did as you said for the Git deployment, and it works just fine.