SyntaxError: Cannot use import statement outside a module

I have a library written in Rust, compiled to wasm and wrapped in typescript. I’m trying to use it in Obsidian plugin. The plugin is started from official example, but compilation errors forced me to change target to ‘es2022’ and format from ‘cjs’ to ‘esm’. Now everything compiles with no warnings, but when I try to use plugin in Obsidian, I get error

Plugin failure: cooklang-obsidian SyntaxError: Cannot use import statement outside a module
    at eval (<anonymous>)
    at app.js:1:2550556
    at e.<anonymous> (app.js:1:2550657)
    at app.js:1:249549
    at Object.next (app.js:1:249654)
    at a (app.js:1:248372)

I have absolutely no idea what to do with it. My package.json:

{
	"name": "cooklang-obsidian",
	"version": "0.5.0",
	"description": "Edit and display Cooklang recipes in Obsidian",
	"main": "main.js",
	"type": "module",
	"scripts": {
		"dev": "node esbuild.config.mjs",
		"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
		"version": "node version-bump.mjs && git add manifest.json versions.json"
	},
	"keywords": [],
	"author": "",
	"license": "MIT",
	"devDependencies": {
		"@codemirror/autocomplete": "^6.11.1",
		"@codemirror/commands": "^6.3.3",
		"@codemirror/lang-javascript": "^6.2.1",
		"@codemirror/language": "^6.10.1",
                ...
	}
}

my esbuild:

import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import {sassPlugin} from "esbuild-sass-plugin";
import wasmLoader from "esbuild-plugin-wasm";

const banner =
	`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = (process.argv[2] === "production");

const context = await esbuild.context({
	banner: {
		js: banner,
	},
	entryPoints: ["src/main.ts"],
	outdir: "dist",
	bundle: true,
	external: [
		"obsidian",
		"electron",
		"@codemirror/autocomplete",
		"@codemirror/collab",
		"@codemirror/commands",
		"@codemirror/language",
		"@codemirror/lint",
		"@codemirror/search",
		"@codemirror/state",
		"@codemirror/view",
		"@lezer/common",
		"@lezer/highlight",
		"@lezer/lr",
		...builtins],
	format: "esm",
	target: "es2022",
	logLevel: "info",
	sourcemap: prod ? false : "inline",
	treeShaking: true,
	minify: prod,
	plugins: [sassPlugin(), wasmLoader.wasmLoader({mode: "embedded"})],
	loader: {'.mp3': 'file'},
});

if (prod) {
	await context.rebuild();
	process.exit(0);
} else {
	await context.watch();
}

Obsidian plugins have to use cjs, esm is not supported