Skip to content

Fail the build when axios is missing (Inertia 3 compatibility)#100

Merged
shanerbaner82 merged 1 commit intomainfrom
fix/require-axios-for-ios-builds
Apr 23, 2026
Merged

Fail the build when axios is missing (Inertia 3 compatibility)#100
shanerbaner82 merged 1 commit intomainfrom
fix/require-axios-for-ios-builds

Conversation

@shanerbaner82
Copy link
Copy Markdown
Contributor

@shanerbaner82 shanerbaner82 commented Apr 23, 2026

Summary

  • NativePHP Mobile intercepts `axios` at bundle time and swaps its transport adapter so HTTP requests route through the embedded PHP runtime. Without axios there's nothing to intercept and outgoing requests never reach PHP.
  • Through Inertia 2 this was always satisfied: `@inertiajs/vue3` / `@inertiajs/react` pulled axios in transitively. Inertia 3 removed the axios dependency in favour of native `fetch`, leaving fresh Inertia 3 projects with a clean build but an app that can't talk to its own backend.
  • This PR makes the Vite plugin throw at `config()` time if axios isn't a declared dependency in the project's `package.json` (or isn't actually present in `node_modules`). The check fires unconditionally — not just under `--mode=ios` — since the same fix applies to any Inertia 3 NativePHP app.

Why check `package.json` and not just the filesystem

A transitive copy of axios can still sit in `node_modules` after the user removes axios from their project (e.g. `@inertiajs/core` itself depends on axios internally). A pure `existsSync` check would pass and the build would silently produce an app that can't reach PHP. Reading the project's `package.json` catches that case — the check fails unless the user has axios declared as a direct dependency of their app.

Error users will see

```
[nativephp/mobile] axios must be declared as a dependency in your package.json.
Inertia 3 removed axios in favour of native fetch; reinstall it so outgoing
requests can be routed through our handler:
npm install axios
Then follow https://inertiajs.com/docs/v3/installation/client-side-setup#using-axios
to tell Inertia to use axios for its client-side requests.
```

Backwards compatibility

  • Apps with axios declared already (any Inertia 2 project, or anything using axios directly): no change.
  • Fresh Inertia 3 projects: previously built cleanly into an app that couldn't make HTTP requests. Now fails the build with a clear fix.

Paired docs

NativePHP/nativephp.com#370 — adds an aside to `mobile/3/getting-started/development.md` covering the same Inertia 3 requirement next to the existing `nativephpMobile` Vite plugin section.

Test plan

  • `npm remove axios` in a vue13 Inertia 3 app, `npm run build` → fails with the error above (a transitive axios in node_modules doesn't mask it).
  • `npm install axios`, `npm run build` → succeeds.
  • Verify Inertia 3 + NativePHP app can make HTTP requests once axios is installed and Inertia is told to use it per the linked docs.

🤖 Generated with Claude Code

@shanerbaner82 shanerbaner82 changed the title Fail iOS builds when axios is missing (Inertia 3 compatibility) Require axios for Inertia 3 compatibility Apr 23, 2026
@shanerbaner82 shanerbaner82 force-pushed the fix/require-axios-for-ios-builds branch from c8c8768 to c306a97 Compare April 23, 2026 20:29
@shanerbaner82 shanerbaner82 changed the title Require axios for Inertia 3 compatibility Fail the build when axios is missing (Inertia 3 compatibility) Apr 23, 2026
@shanerbaner82 shanerbaner82 force-pushed the fix/require-axios-for-ios-builds branch from c306a97 to 34a5096 Compare April 23, 2026 20:34
shanerbaner82 added a commit to NativePHP/nativephp.com that referenced this pull request Apr 23, 2026
NativePHP Mobile intercepts axios at bundle time to route HTTP requests
through the embedded PHP runtime. Inertia 3 removed axios in favour of
native fetch, so fresh Inertia 3 projects fail the NativePHP build until
they declare axios as a direct dependency.

Adds an aside to mobile/3/getting-started/development in the section that
already introduces the nativephpMobile Vite plugin — that's the natural
home for build-time concerns — with the single `npm install axios` step
and a link to Inertia's client-side-setup docs for wiring it up.

Pairs with NativePHP/mobile-air#100 which makes the Vite plugin fail
early with an error pointing here and at the Inertia docs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
NativePHP Mobile intercepts `axios` at bundle time and swaps its transport
adapter for one that routes requests through the embedded PHP runtime.
On iOS that hits our `WKURLSchemeHandler`; on Android it hits the
`WebViewClient.shouldInterceptRequest` bridge. Either way, if axios isn't
installed there's nothing to intercept and outgoing HTTP requests fail to
reach PHP.

Through Inertia 2 this was always a given: `@inertiajs/vue3` and
`@inertiajs/react` both pulled axios in as a transitive dependency, so
the interception just worked. Inertia 3 removed axios in favour of native
`fetch` (see
https://inertiajs.com/docs/v3/installation/client-side-setup#using-axios),
so fresh Inertia 3 projects build cleanly but produce an app that can't
talk to its own backend.

Fail fast at `config()` time with a clear error that tells users exactly
what to install and links to the Inertia adapter docs. The check runs
unconditionally (not only under `--mode=ios`) so users hitting the same
Inertia-3-shaped failure on either platform get the same helpful nudge.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@shanerbaner82 shanerbaner82 force-pushed the fix/require-axios-for-ios-builds branch from 34a5096 to 23b047b Compare April 23, 2026 20:38
@shanerbaner82 shanerbaner82 merged commit feea206 into main Apr 23, 2026
0 of 5 checks passed
@shanerbaner82 shanerbaner82 deleted the fix/require-axios-for-ios-builds branch April 23, 2026 20:43
shanerbaner82 added a commit to NativePHP/nativephp.com that referenced this pull request Apr 23, 2026
…#370)

NativePHP Mobile intercepts axios at bundle time to route HTTP requests
through the embedded PHP runtime. Inertia 3 removed axios in favour of
native fetch, so fresh Inertia 3 projects fail the NativePHP build until
they declare axios as a direct dependency.

Adds an aside to mobile/3/getting-started/development in the section that
already introduces the nativephpMobile Vite plugin — that's the natural
home for build-time concerns — with the single `npm install axios` step
and a link to Inertia's client-side-setup docs for wiring it up.

Pairs with NativePHP/mobile-air#100 which makes the Vite plugin fail
early with an error pointing here and at the Inertia docs.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant