Here is a simple example using ECMAScript modules, buffer.js:
import { Buffer } from 'node:buffer';
// Creates a zero-filled Buffer of length 10.
const buf1 = Buffer.alloc(10);
Compiled it:
# google-closure-compiler --js buffer.js --language_in ECMASCRIPT_2019
buffer.js:1:0: ERROR - [JSC_INVALID_MODULE_PATH] Invalid module path "node:buffer" for resolution mode "BROWSER"
1| import { Buffer } from 'node:buffer';
^
1 error(s), 0 warning(s)
Also:
# google-closure-compiler --js buffer.js --module_resolution=NODE
buffer.js:1:0: ERROR - [JSC_JS_MODULE_LOAD_WARNING] Failed to load module "node:buffer"
1| import { Buffer } from 'node:buffer';
^
Works with CommonJS modules though:
const { Buffer } = require('node:buffer');
// Creates a zero-filled Buffer of length 10.
const buf1 = Buffer.alloc(10);
Result:
# google-closure-compiler --js buffer-cjs.js
const {Buffer}=require("node:buffer"),buf1=Buffer.alloc(10);
Would appreciate any clarity on whether ESM is supported, and if so, how to enable it. Tried other things, looked up the documentation and searched online, but no solution found.