So after watching this video I decided to move away from import maps to esbuild. It only worked when I added an esbuild.config.mjs with the following js:
const path = require('path')
const rails = require('esbuild-rails')
require("esbuild").build({
entryPoints: ["application.js"],
bundle: true,
outdir: path.join(process.cwd(), "app/assets/builds"),
absWorkingDir: path.join(process.cwd(), "app/javascript"),
plugins: [rails()],
}).catch(() => process.exit(1))
Thanks.