- How do I install spatie/shiki-php in a Laravel application?
- Install the PHP package with composer require spatie/shiki-php. Composer alone is not enough: you also need a Node 20+ runtime in the environment and the shiki npm package installed alongside your project. In Laravel the recommended path is to pull it in through spatie/laravel-markdown rather than calling Shiki::highlight() directly from controllers or Blade views.
- Does spatie/shiki-php require Node.js to be installed?
- Yes. This package is a thin PHP wrapper that shells out to the Node.js Shiki highlighter, so a Node runtime must exist in every environment where highlighting runs, including CI and production. If the shiki npm package is missing, the output silently loses the <pre> element, which is a confusing failure mode to debug. Container images and serverless runtimes need explicit Node installation, and NVM setups usually require a symlink into a directory like /usr/local/bin or /opt/homebrew/bin so the binary can be found.
- Which PHP and Laravel versions does spatie/shiki-php support?
- The package targets PHP 8 and above; PHP 7.4 support was dropped in version 2.3.2. Laravel integration is provided by first-party Spatie companion packages such as spatie/laravel-markdown and spatie/commonmark-shiki-highlighter. Because the public API has churned across Shiki v1, v2 and v4 upgrades, pin both the Composer and npm versions and read the changelog before upgrading.
- How do I highlight code blocks in Laravel Markdown using Shiki?
- Use spatie/laravel-markdown and let it own the CommonMark pipeline so Shiki is applied at the renderer layer instead of scattered through your application code. If you are outside Laravel but still on league/commonmark, spatie/commonmark-shiki-highlighter gives you the same benefit as a renderer extension. Both approaches keep highlighting logic in one place and make it far easier to swap or cache later.
- Why is the pre element missing from my Shiki highlighted output?
- The README is explicit about this: without the shiki npm package installed in the project, the rendered output lacks the surrounding <pre> element. The PHP package itself installs cleanly, so the failure appears only at render time and produces HTML that looks subtly wrong rather than throwing an error. Verify the npm dependency in every environment, not just locally, and add a smoke test that asserts on the expected markup.
- Is spatie/shiki-php fast enough for request-time highlighting?
- Every highlight() call spawns a fresh Node process, so cost scales with Node startup time rather than with the snippet alone. That is acceptable for a few dozen code blocks per page render, such as a documentation or blog article, but it is a poor fit for high-RPS endpoints or bulk backfills. The safer architecture is to highlight at content-publish time or in a queued job and store the resulting HTML.
- Which languages and themes can I use with spatie/shiki-php?
- Shiki ships with over 100 languages out of the box, and this package adds Blade and Antlers on top. Themes like github-light are supported directly, and you can point the package at a custom VS Code theme JSON file using an absolute path. If you rely on custom themes, plan who maintains those theme assets and version them alongside your content.
- How do I deploy spatie/shiki-php in Docker, Heroku or a serverless environment?
- Your base image or buildpack must install Node 20+ and the shiki npm package, since the PHP package cannot highlight anything without them. Serverless and edge runtimes generally need a custom layer or bundled binary, and Heroku-style deployments need a buildpack that provides Node. Also confirm that the node binary is on the PATH the PHP process sees, because node discovery is host-dependent and often breaks only in production.
- Can spatie/shiki-php handle very large code blocks?
- Large inputs have historically failed with a posix_spawn() failed: Argument list too long error, and version 2.3.3 addressed this by passing the payload over stdin via proc_open instead of as OS arguments. Even so, huge snippets still pay the full Node startup cost on every call. For bulk processing, chunk the work and run it offline or in background jobs rather than inside a web request.
- What are the alternatives to spatie/shiki-php for highlighting code in PHP?
- Within the Spatie ecosystem, spatie/laravel-markdown and spatie/commonmark-shiki-highlighter wrap the same Shiki engine but integrate at the renderer layer, which is usually the better choice for Laravel apps. If you want to avoid a Node runtime entirely, look at pure-PHP highlighters, accepting lower grammar fidelity than Shiki's editor-grade output. Weigh the trade-off against this package's small community and its history of breaking changes before committing.