0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

vercel dev コマンドで出た謎の Cannot find module エラー対処備忘録

Last updated at Posted at 2024-08-20

前提

vercel serverless functions として  api/a.ts が用意してあり、ローカルで起動するために vercel dev コマンド を使う
next.jsは使っていない

発生したこと

ローカルで起動して http://localhost/a にアクセスすると、
502: BAD_GATE_WAY になり、以下のような謎のエラーが発生

Error: Function `api/a.ts` failed with exit code 1
node:internal/modules/cjs/loader:1148
  throw err;
  ^

Error: Cannot find module '/Users/me/Library/Application'
Require stack:
- internal/preload
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at internalRequire (node:internal/modules/cjs/loader:176:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1563:5)
    at loadPreloadModules (node:internal/process/pre_execution:730:5)
    at setupUserModules (node:internal/process/pre_execution:206:5)
    at prepareExecution (node:internal/process/pre_execution:159:5)
    at prepareMainThreadExecution (node:internal/process/pre_execution:54:10)
    at node:internal/main/run_main_module:11:19 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}

Node.js v20.14.0
Error: Function `api/a.ts` failed with exit code 1

なぜか Error: Cannot find module '/Users/me/Library/Application' という変な場所を見に行っているが、そのようなモジュールはない

原因不明だが直せた方法

package.jsonのdevDependenciesにvercelを追加したら直った

    "vercel": "^36.0.0",

社内で他の方はglobal installで問題なく、自分だけ発生したので根本的な原因はわからない

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?