esbuildのwasmを使う

  • このエントリーをはてなブックマークに追加

Windowsではコード署名が付いていないEXEを実行できない環境があります。
esbuildのexeファイルはコード署名がありません。そしてコード署名には対応しないことがIssueでやりとりされています。(参考情報を参照)

package.jsonoverrides機能を使って以下の定義を追加します。

"overrides": {
"esbuild": "npm:esbuild-wasm@latest"
}

確認した環境

vuepressを使っているところで、1.8系から1.9系の変更でesbuildを使うようになり、特定の環境でこけるようになりました。
以下がこけた時のログです。

npm install --save vuepress
npm WARN cleanup Failed to remove some directories [
npm WARN cleanup [
npm WARN cleanup 'C:\\Users\\User1\\AppData\\Local\\Temp\\work1\\node_modules',
npm WARN cleanup [Error: EPERM: operation not permitted, rmdir 'C:\Users\User1\AppData\Local\Temp\work1\node_modules\browserify-sign\node_modules'] {
npm WARN cleanup errno: -4048,
npm WARN cleanup code: 'EPERM',
npm WARN cleanup syscall: 'rmdir',
npm WARN cleanup path: 'C:\\Users\\User1\\AppData\\Local\\Temp\\work1\\node_modules\\browserify-sign\\node_modules'
npm WARN cleanup }
npm WARN cleanup ],
npm WARN cleanup [
npm WARN cleanup 'C:\\Users\\User1\\AppData\\Local\\Temp\\work1\\node_modules\\@vuepress\\core',
npm WARN cleanup [Error: EPERM: operation not permitted, rmdir 'C:\Users\User1\AppData\Local\Temp\work1\node_modules\@vuepress\core'] {
npm WARN cleanup errno: -4048,
npm WARN cleanup code: 'EPERM',
npm WARN cleanup syscall: 'rmdir',
npm WARN cleanup path: 'C:\\Users\\User1\\AppData\\Local\\Temp\\work1\\node_modules\\@vuepress\\core'
npm WARN cleanup }
npm WARN cleanup ]
npm WARN cleanup ]
npm ERR! code 1
npm ERR! path C:\Users\User1\AppData\Local\Temp\work1\node_modules\esbuild
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node install.js
npm ERR! node:child_process:924
npm ERR! throw err;
npm ERR! ^
npm ERR!
npm ERR! <ref *1> Error: spawnSync C:\Users\User1\AppData\Local\Temp\work1\node_modules\esbuild-windows-64\esbuild.exe UNKNOWN
npm ERR! at Object.spawnSync (node:internal/child_process:1110:20)
npm ERR! at spawnSync (node:child_process:871:24)
npm ERR! at Object.execFileSync (node:child_process:914:15)
npm ERR! at Object.<anonymous> (C:\Users\User1\AppData\Local\Temp\work1\node_modules\esbuild\bin\esbuild:108:26)
npm ERR! at Module._compile (node:internal/modules/cjs/loader:1256:14)
npm ERR! at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
npm ERR! at Module.load (node:internal/modules/cjs/loader:1119:32)
npm ERR! at Module._load (node:internal/modules/cjs/loader:960:12)
npm ERR! at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
npm ERR! at node:internal/main/run_main_module:23:47 {
npm ERR! errno: -4094,
npm ERR! code: 'UNKNOWN',
npm ERR! syscall: 'spawnSync C:\\Users\\User1\\AppData\\Local\\Temp\\work1\\node_modules\\esbuild-windows-64\\esbuild.exe',
npm ERR! path: 'C:\\Users\\User1\\AppData\\Local\\Temp\\work1\\node_modules\\esbuild-windows-64\\esbuild.exe',
npm ERR! spawnargs: [ '--version' ],
npm ERR! error: [Circular *1],
npm ERR! status: null,
npm ERR! signal: null,
npm ERR! output: null,
npm ERR! pid: 0,
npm ERR! stdout: null,
npm ERR! stderr: null
npm ERR! }
npm ERR!
npm ERR! Node.js v18.17.1
npm ERR! node:internal/errors:865
npm ERR! const err = new Error(message);
npm ERR! ^
npm ERR!
npm ERR! Error: Command failed: node C:\Users\User1\AppData\Local\Temp\work1\node_modules\esbuild\bin\esbuild --version
npm ERR! node:child_process:924
npm ERR! throw err;
npm ERR! ^
npm ERR!
npm ERR! <ref *1> Error: spawnSync C:\Users\User1\AppData\Local\Temp\work1\node_modules\esbuild-windows-64\esbuild.exe UNKNOWN
npm ERR! at Object.spawnSync (node:internal/child_process:1110:20)
npm ERR! at spawnSync (node:child_process:871:24)
npm ERR! at Object.execFileSync (node:child_process:914:15)
npm ERR! at Object.<anonymous> (C:\Users\User1\AppData\Local\Temp\work1\node_modules\esbuild\bin\esbuild:108:26)
npm ERR! at Module._compile (node:internal/modules/cjs/loader:1256:14)
npm ERR! at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
npm ERR! at Module.load (node:internal/modules/cjs/loader:1119:32)
npm ERR! at Module._load (node:internal/modules/cjs/loader:960:12)
npm ERR! at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
npm ERR! at node:internal/main/run_main_module:23:47 {
npm ERR! errno: -4094,
npm ERR! code: 'UNKNOWN',
npm ERR! syscall: 'spawnSync C:\\Users\\User1\\AppData\\Local\\Temp\\work1\\node_modules\\esbuild-windows-64\\esbuild.exe',
npm ERR! path: 'C:\\Users\\User1\\AppData\\Local\\Temp\\work1\\node_modules\\esbuild-windows-64\\esbuild.exe',
npm ERR! spawnargs: [ '--version' ],
npm ERR! error: [Circular *1],
npm ERR! status: null,
npm ERR! signal: null,
npm ERR! output: null,
npm ERR! pid: 0,
npm ERR! stdout: null,
npm ERR! stderr: null
npm ERR! }
npm ERR!
npm ERR! Node.js v18.17.1
npm ERR!
npm ERR! at checkExecSyncError (node:child_process:885:11)
npm ERR! at Object.execFileSync (node:child_process:921:15)
npm ERR! at validateBinaryVersion (C:\Users\User1\AppData\Local\Temp\work1\node_modules\esbuild\install.js:94:32)
npm ERR! at C:\Users\User1\AppData\Local\Temp\work1\node_modules\esbuild\install.js:240:5 {
npm ERR! status: 1,
npm ERR! signal: null,
npm ERR! output: [
npm ERR! null,
npm ERR! Buffer(0) [Uint8Array] [],
npm ERR! Buffer(1309) [Uint8Array] [
npm ERR! ... 1209 more items
npm ERR! ]
npm ERR! ],
npm ERR! pid: 38656,
npm ERR! stdout: Buffer(0) [Uint8Array] [],
npm ERR! stderr: Buffer(1309) [Uint8Array] [
npm ERR! ... 1209 more items
npm ERR! ]
npm ERR! }
npm ERR!
npm ERR! Node.js v18.17.1

この環境でoverrides設定を入れればwasm版で動くようになりました。

参考