Deploying a phoenix + esbuild + react app

I’m trying to deploy a phoenix 1.6 app with react, on the client side. It builds fine locally but I can’t seem to get it to build remotely.

> ERROR [builder 13/17] RUN mix assets.deploy                                                                                                            1.3s
------
 > [builder 13/17] RUN mix assets.deploy:
#22 0.892 
#22 0.892 14:41:34.916 [debug] Downloading esbuild from https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.29.tgz
#22 1.243 ✘ [ERROR] Could not resolve "react"
#22 1.243 
#22 1.243     js/app.js:3:18:
#22 1.243       3 │ import React from 'react';
#22 1.243         ╵                   ~~~~~~~
#22 1.243 
#22 1.243   You can mark the path "react" as external to exclude it from the bundle, which will remove this error.

Following the suggestion and excluding it from the bundle leads to:

Uncaught Error: Dynamic require of "react" is not supported

I tried following the guides (Asset Management — Phoenix v1.6.12) but that didn’t help much either.