Since
v1.26, Deno introduces npm improvements without older --compat
option.
For example, Prettier can run on Deno with a wrapper as follows:
#!/usr/bin/env -S deno run --allow-read --allow-env --allow-write --allow-sys
import("npm:prettier/internal/cli.mjs")
.then(cli => cli.run(Deno.args));
This is rewritten along with its node.js version bundled with Prettier npm.
Since a wrapper runs outside of node polyfilled env, it needs to be written in a Deno way:
- use shebang for deno with lengthy options
- use
import()
withnpm:
resolution instead ofrequire()
- replace
process.argv
withDeno.args
Original script has an extra version check, removed because it depends on Node.js.
Save the above as “prettier” with exec bits, and you can run on Deno.
⁋ Nov 10, 2022↻ Feb 6, 2025

中馬崇尋
Chuma Takahiro
Chuma Takahiro