running npm script from within npm script fails with ESM error

here are the scripts from my package.json:
  "scripts": {
    "build": "next build",
    "dev": "next dev",
    "lint": "next lint",
    "start": "next start",
    "test:run": "vitest",
    "test": "firebase emulators:exec 'npm run test:run'"
  },


when I run
npm run test
I get the following error:

> t3-true-finals@0.1.0 test
> firebase emulators:exec 'npm run test:run'

i  emulators: Starting emulators: auth, firestore, storage
i  firestore: Firestore Emulator logging to firestore-debug.log
✔  firestore: Firestore Emulator UI websocket is running on 9150.
i  Running script: npm run test:run

> t3-true-finals@0.1.0 test:run /Users/tom/Development/projects/t3-true-finals
> vitest

node:internal/modules/cjs/loader:979
    throw new ERR_REQUIRE_ESM(filename, true);
    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/tom/Development/projects/t3-true-finals/node_modules/vitest/vitest.mjs not supported.
Instead change the require of /Users/tom/Development/projects/t3-true-finals/node_modules/vitest/vitest.mjs to a dynamic import() which is available in all CommonJS modules.
    at Function.runMain (pkg/prelude/bootstrap.js:1983:12) {
  code: 'ERR_REQUIRE_ESM'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! t3-true-finals@0.1.0 test:run: `vitest`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the t3-true-finals@0.1.0 test:run script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/tom/.npm/_logs/2023-03-03T02_28_14_203Z-debug.log
Was this page helpful?