AWS-CDKで今まで何も問題なくデプロイできていたTypeScriptのLambda関数で、ある日突然デプロイ時にエラーENOENT: no such file or directory
が発生するようになりました。
% cdk deploy
Bundling asset hogeStack/fuga/Code/Stage…
Building hoge.ts…
🚨 Build failed.
Error: ENOENT: no such file or directory, open ‘/asset-input/node_modules/aws-amplify/lib/index.js’
Error: ENOENT: no such file or directory, open ‘/asset-input/node_modules/aws-amplify/lib/index.js’
Failed to bundle asset hogeStack/fuga/Code/Stage, bundle output is located at /Users/a/work/cdk/cdk.out/bundling-temp-52790e2ed2ab60b0cf0a67c80b7d81e7a04f6181172a1a2161b2d92a5411d441-error: Error: docker exited with status 1
Subprocess exited with error 1
rm -r node_modules && yarn install
してみても解消しません。少し調べたところ、Lambdaのデプロイに使用しているaws-lambda-nodejsモジュールが、ParcelというJavaScriptバンドラを使ってTypeScriptへのトランスパイルをしていることがわかりました。
Parcelはキャッシュを使うようで、CDKディレクトリの中に.parcel-cache
という名前のディレクトリを発見しました。これを削除してからcdk deploy
したところ、エラーは無事起きなくなりました。