Node.js errors
Reproduced on pinned Node images, fixed and re-checked.
- ReferenceError: AbortController is not defined
ReferenceError: AbortController is not defined:古い Node で AbortController が無いときの直し方
node:14.16.1-alpine · use of global AbortController on Node < 15タイムアウトやキャンセル処理で AbortController を使ったら、古い Node で次のエラーが出て落ちることがあります。
Node.js 4 min read - Cannot use import statement outside a module
Cannot use import statement outside a module の直し方(Node.js)
node:20-alpine · import in CommonJSNode でファイルを実行したら、import の行で次のエラーが出て止まることがあります。
Node.js 4 min read - TypeError: crypto.hash is not a function
TypeError: crypto.hash is not a function:新しい Node の crypto.hash が古い版で無いときの直し方
node:20.11.1-alpine · call to crypto.hash on Node < 20.12 / 21.0-21.6新しいドキュメントやサンプルで見かけた crypto.hash() をそのまま使ったら、手元やサーバーの Node で次のエラーが出て落ちることがあります。
Node.js 4 min read - TypeError: crypto.randomUUID is not a function
TypeError: crypto.randomUUID is not a function:古い Node で randomUUID が無いときの直し方
node:14.16.1-alpine · call to crypto.randomUUID on Node < 14.17UUID を生成しようと crypto.randomUUID() を呼んだら、古い Node で次のエラーが出て落ちることがあります。
Node.js 4 min read - __dirname is not defined in ES module scope
__dirname is not defined in ES module scope の直し方(Node.js)
node:20-alpine · __dirname in an ESM fileNode で .js を実行したら、次のエラーで落ちることがあります。
Node.js 5 min read - ERR_MODULE_NOT_FOUND
ERR_MODULE_NOT_FOUND: ESM の相対 import に拡張子が無いときの直し方(Node.js)
node:20-alpine · extensionless relative import in ESMNode で .js を実行したら、次のエラーで落ちることがあります。
Node.js 5 min read - ERR_OSSL_EVP_UNSUPPORTED
digital envelope routines::unsupported の直し方(Node.js の ERR_OSSL_EVP_UNSUPPORTED)
node:18-alpine · webpack 4 / CRA · OpenSSL 3 hashingnpm run build(webpack、Create React App、vue-cli、Angular など)が、次のエラーで突然落ちるようになったら、原因はほぼ確実に Node のバージョンを上げたことです。
Node.js 5 min read - ERR_REQUIRE_ASYNC_MODULE
require() cannot be used on an ESM graph with top-level await の直し方(Node.js の ERR_REQUIRE_ASYNC_MODULE)
node:22.12.0-alpine · require() of top-level await ESMNode を新しめのバージョンに上げたあと、CommonJS から ESM を require() すると次のエラーで落ちることがあります。
Node.js 3 min read - ERR_REQUIRE_ESM
require() of ES Module not supported の直し方(Node.js の ERR_REQUIRE_ESM)
node:18-alpine · require() in CommonJSCommonJS(.cjs や require() を使うコード)から ESM 専用モジュールを読み込もうとすると、次のエラーで落ちます。
Node.js 3 min read - ERR_UNKNOWN_FILE_EXTENSION
Unknown file extension ".ts" の直し方(Node.js で TypeScript を直接実行したとき)
node:22.6.0-alpine · node app.ts (no loader)node app.ts のように TypeScript ファイルを Node で直接実行しようとして、次のエラーで止まることがあります。
Node.js 4 min read - ERR_UNSUPPORTED_DIR_IMPORT
ERR_UNSUPPORTED_DIR_IMPORT: ESM でディレクトリを import したときの直し方(Node.js)
node:20-alpine · directory import in ESMESM のプロジェクトで、ディレクトリを指す相対 import を実行したら、次のエラーで落ちることがあります。
Node.js 4 min read - the default configuration file is now eslint.config.js
ESLint couldn't find an eslint.config.js file の直し方(ESLint 9 で .eslintrc が既定で読まれなくなった)
node:22.23.1-alpine · ESLint 9.0.0 (flat config default; .eslintrc no longer read by default) · running eslint 9 with only a .eslintrc.* file (no eslint.config.js), typically after a clean install pulls ESLint 9これまで動いていた .eslintrc.json(.eslintrc.js / .eslintrc.yml も同じ)のまま eslint を実行すると、lint が始まる前に次のエラーで止まることがあります。
Node.js 7 min read - ERR_UNSUPPORTED_ESM_URL_SCHEME
ERR_UNSUPPORTED_ESM_URL_SCHEME の直し方(Windows で絶対パスを動的 import して落ちるとき)
node:20 · Node core (node:url pathToFileURL) · dynamic import() of a Windows drive-letter absolute path parsed as URL scheme 'c:'await import(...) に絶対パスの文字列を渡すコードが、macOS や Linux では動くのに、Windows でだけ次のエラーで落ちることがあります。
Node.js 5 min read - exports is not defined in ES module scope
exports is not defined in ES module scope の直し方(Node.js)
node:20-alpine · exports under type:module (tsc CJS output)Node で .js を実行したら、次のエラーで落ちることがあります。
Node.js 4 min read - ERR_PACKAGE_PATH_NOT_EXPORTED
ERR_PACKAGE_PATH_NOT_EXPORTED の直し方(パッケージのサブパスを import して落ちるとき)
node:20 · uuid v8+ · deep subpath import blocked by package exports fieldrequire(または import)でパッケージの中の深い場所を読み込もうとすると、次のエラーで止まることがあります。
Node.js 5 min read - ReferenceError: fetch is not defined
ReferenceError: fetch is not defined:古い Node で global fetch が無いときの直し方
node:16.20.2-alpine · call to global fetch on Node < 18 (default)手元では動いていたコードを CI や本番の古い Node で走らせたら、fetch を呼んだ行で次のエラーが出て落ちることがあります。
Node.js 5 min read - Unexpected identifier 'assert'
SyntaxError: Unexpected identifier 'assert':JSON import の assert を with に直す(Node.js)
node:22-alpine · JSON import assert attribute on Node 22+手元では動いていたコードを Node 22 以降で実行したら、次のエラーで落ちることがあります。
Node.js 4 min read - module is not defined in ES module scope
module is not defined in ES module scope の直し方(Node.js)
node:20.20.2-alpine · module.exports in an ESM fileNode で .js を実行したら、module.exports の行で次のエラーが出て落ちることがあります。
Node.js 5 min read - Named export not found
does not provide an export named / Named export not found の直し方(Node.js)
node:20-alpine · named import from CommonJSES Module(ESM)から名前付き import をしたら、次のどちらかのエラーで止まることがあります。
Node.js 3 min read - NODE_MODULE_VERSION
NODE_MODULE_VERSION mismatch の直し方(ネイティブ addon を別の Node 版で読み込んだとき)
node:20 · native addon (better-sqlite3 等) · native addon ABI mismatch across Node versionsnode でアプリを起動した瞬間、require の行で次のエラーが出て落ちることがあります。
Node.js 7 min read - ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING
ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING の直し方(node_modules の中の .ts は実行されない)
node:24.18.0-alpine · a dependency ships .ts as its entry point; Node deliberately does not type-strip under node_modules and no flag overrides itnode app.ts は動いていたのに、あるライブラリを import した瞬間に次のエラーで止まります。
Node.js 5 min read - Cannot find module 'node:fs'
Cannot find module 'node:fs':node: プレフィックスが古い Node で通らないときの直し方
node:14.17.6-alpine · require of node: prefixed builtin on Node < 14.18新しめのコードをそのまま古い Node で動かしたら、組み込みモジュールのはずなのに次のエラーで落ちることがあります。
Node.js 4 min read - AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal
Expected values to be strictly deep-equal の直し方(node:sqlite の行は null プロトタイプ)
node:24.13.0-alpine · node:sqlite returns null-prototype row objects; assert.deepStrictEqual compares prototypes, so rows fail against plain object literals even when every key and value is equalnode:sqlite の DatabaseSync#prepare().all()/.get() は null プロトタイプの行を返す。値が同じでも assert.deepStrictEqual はプロトタイプを比較するので、オブジェクトリテラルと比べると actual/expected が同一表示のまま落ちる。比較の前に各行を .map(r => ({ ...r })) で素のオブジェクトへ写すと通る。
Node.js 6 min read - can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync
npm ci can only install packages when your package.json and package-lock.json are in sync の直し方(CI だけ落ちるロックずれ)
node:22.23.1-alpine · npm 10.9.8 (npm ci requires package.json and package-lock.json to be in sync) · editing package.json without committing the regenerated package-lock.json (or a stale lock from another branch); local npm install rewrites the lock silently, but CI's npm ci refuses the mismatch with EUSAGE手元では npm install が通るのに、CI で npm ci を実行すると、パッケージを1つも入れないまま次のエラーで止まることがあります。
Node.js 6 min read - can only install with an existing package-lock.json
The npm ci command can only install with an existing package-lock.json の直し方(ロックが無い環境で npm ci)
node:22.23.1-alpine · npm 10.9.8 (npm ci requires a committed package-lock.json; it does not generate one) · running npm ci where no package-lock.json exists — commonly the lock is gitignored, never generated, or npm ci is run in a subdirectory without the lockCI やコンテナで npm ci を実行すると、依存を1つも入れないまま次のエラーで止まることがあります。
Node.js 4 min read - ERESOLVE unable to resolve dependency tree
ERESOLVE unable to resolve dependency tree の直し方(npm install が peer dependency の衝突で止まる)
node:22 · npm 7+ / react-dom · peer dependency conflict on npm installnpm install が、パッケージを1つも入れないまま次のエラーで止まることがあります。
Node.js 7 min read - ERR_PACKAGE_IMPORT_NOT_DEFINED
ERR_PACKAGE_IMPORT_NOT_DEFINED の直し方(#始まりの import を package.json の imports で宣言する)
node:22.23.1-alpine · Node.js subpath imports (# specifiers must be declared in the package.json imports field) · importing a #-prefixed specifier without an imports map in package.json — copying code that used internal imports, or relying on tsconfig paths which Node does not read at runtime#foo のように # で始まる名前を import すると、次のエラーで止まることがあります。
Node.js 4 min read - require is not defined in ES module scope
require is not defined in ES module scope の直し方(Node.js)
node:20-alpine · require() in an ESM fileNode で .js を実行したら、次のエラーで落ちることがあります。
Node.js 4 min read - ReferenceError: structuredClone is not defined
ReferenceError: structuredClone is not defined:古い Node で structuredClone が無いときの直し方
node:16.20.2-alpine · call to global structuredClone on Node < 17オブジェクトを深くコピーしようと structuredClone を呼んだら、古い Node で次のエラーが出て落ちることがあります。
Node.js 4 min read - can only be default-imported using the 'esModuleInterop' flag
error TS1259: Module '...' can only be default-imported using the 'esModuleInterop' flag の直し方
node:22.23.1-alpine · TypeScript (esModuleInterop defaults to false for module: commonjs; default-importing an export= CommonJS module needs it enabled) · default-importing a CommonJS (export =) module under a module: commonjs tsconfig without esModuleInterop — common in hand-written or older tsconfig where the flag is absent (tsc --init and module: nodenext enable it)CommonJS のライブラリを import x from "..." の形(default import)で読み込むと、tsc が次のエラーで止まることがあります。
Node.js 5 min read - TS5109: Option 'moduleResolution' must be set to 'NodeNext'
error TS5109: Option 'moduleResolution' must be set to 'NodeNext' の直し方(TypeScript 5.2 で module と moduleResolution の組み合わせが強制された)
node:22.23.1-alpine · TypeScript 5.2+ (module: NodeNext/Node16 requires a matching moduleResolution; accepted through 5.1) · tsc with module: NodeNext (or Node16) paired with moduleResolution: node, after TypeScript is upgraded to 5.2 or later (5.1 accepted the same tsconfig)これまで通っていた tsconfig.json のまま tsc を実行すると、型チェックが始まる前に次のエラーで止まることがあります。
Node.js 5 min read - SyntaxError: Invalid or unexpected token
SyntaxError: Invalid or unexpected token の直し方(Node の型ストリッピングは decorator を実行できない)
node:24.18.0-alpine · Node's strip-only TypeScript cannot erase or transform decorators; @decorator surfaces as a generic SyntaxError, and --experimental-transform-types does not help (removed in Node 26)node app.ts の decorator(@Injectable() など)が SyntaxError: Invalid or unexpected token でその行を指して止まる。Node の型ストリッピングは decorator を消せず変換もできず、--experimental-transform-types でも直らない(Node 26 で削除)。tsc / tsx で変換して実行する。
Node.js 7 min read - has been removed. Please remove it from your configuration
error TS5102: Option '...' has been removed の直し方(TypeScript が削除した compiler option と、ignoreDeprecations が効かなくなる境界)
node:22.23.1-alpine · TypeScript 5.6+ (importsNotUsedAsValues / target ES3 removed in 5.6; ignoreDeprecations no longer applies) · tsc with a removed compilerOption (e.g. importsNotUsedAsValues, target ES3) after upgrading TypeScript to 5.6 or later (removal boundary; deprecated with an ignoreDeprecations escape through 5.5)TypeScript を上げてから、tsc がソースを型チェックする前に tsconfig.json のオプションで止まることがあります。
Node.js 5 min read - ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX
ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX の直し方(Node が enum を実行できない)
node:24.18.0-alpine · Node's built-in TypeScript support is strip-only; enum emits runtime code so it cannot be erasednode app.ts が動くようになったので TypeScript をそのまま渡したら、enum のところで止まった、というエラーです。
Node.js 7 min read - does not provide an export named 'styleText'
does not provide an export named 'styleText' の直し方(util.styleText が import できない)
node:20.11.1-bookworm · util.styleText imported on a Node older than 20.12.0 / 21.7.0 (minor-version boundary inside an LTS line)Node だけで色付きのログを出せる util.styleText を使おうとすると、次のエラーで止まることがあります。
Node.js 9 min read
条件に一致するエラーはありません。フィルタを緩めてください。