Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save s-show/2801557ba516b2c8508cbc357617dfc1 to your computer and use it in GitHub Desktop.
Save s-show/2801557ba516b2c8508cbc357617dfc1 to your computer and use it in GitHub Desktop.
"UnhandledPromiseRejectionWarning"エラーの対処

npm run start コマンドを実行したら以下のエラーが発生した。

> docs@1.0.0 start /Users/shimizu/mon-shin-dialog-sample/docs
> webpack-cli serve --open --mode development

(node:53807) UnhandledPromiseRejectionWarning: Error: No valid exports main found for '/Users/shimizu/mon-shin-dialog-sample/docs/node_modules/colorette'
    at resolveExportsTarget (internal/modules/cjs/loader.js:625:9)
    at applyExports (internal/modules/cjs/loader.js:502:14)
    at resolveExports (internal/modules/cjs/loader.js:551:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:657:22)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:960:27)
    at Function.Module._load (internal/modules/cjs/loader.js:855:27)
    at Module.require (internal/modules/cjs/loader.js:1033:19)
    at require (/Users/shimizu/mon-shin-dialog-sample/docs/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.get colors [as colors] (/Users/shimizu/mon-shin-dialog-sample/docs/node_modules/webpack-cli/lib/utils/index.js:3:16)
    at Object.error (/Users/shimizu/mon-shin-dialog-sample/docs/node_modules/webpack-cli/lib/utils/logger.js:5:58)
(node:53807) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:53807) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

エラーの内容は、async 関数内で throw されたエラーや、reject された Promise が .catch() などでハンドリングされずに reject されたままになっていると、unhandled rejction (または unhandled promise rejction )というエラーが起きるというもの。

自分のコードでは async 関数を使っていないが、エラーメッセージに No valid exports main found for '/Users/shimizu/mon-shin-dialog-sample/docs/node_modules/colorette' とあったので、ncu -u コマンドで依存パッケージを更新した。しかし、エラーが解消されなかった。

そこで色々と検索したところ、似たようなエラーに遭遇した人に対し「その問題は Node のバージョン 14.5 で解消している」という回答があったので、nvm use latest で Node のバージョンを 13.6.0 から 16.3.0 に上げたら解消された。

ーーー

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment