Create a action using running node with esm

How to create a github action using node with ESM (index.mjs) ?

The action runner tries to run the code as cjs:

internal/modules/cjs/loader.js:1029
5
  throw new ERR_REQUIRE_ESM(filename);
6
  ^
7

8
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/runner/work/template-sync-action/template-sync-action/index.mjs
9
    at Object.Module._extensions..mjs (internal/modules/cjs/loader.js:1029:9)
10
    at Module.load (internal/modules/cjs/loader.js:815:32)
11
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
12
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
13
    at internal/main/run_main_module.js:17:11 {
14
  code: 'ERR_REQUIRE_ESM'
15
}

Hi @arlac77

Have you found a solution for using ESM with Node actions?

From what I’ve been reading, the only way is using @vercel/ncc. GitHub uses it for its TypeScript and JavaScript action templates:

Related: