Gojabako ZoneKei Ito

AWSの開発でたまに遭うエラーと原因

に公開に更新)履歴 (6)

また遭遇しそうなやつを記録するやつです。環境はAWS Lambda, Node.js 14.xでSDKはv3を使っています。npmパッケージはバンドルせずLayerに入れてimport (require)しています。

crypto.getRandomValues() not supported

原因から察するにたぶんSQSに限りませんがSQSでSendMessageBatchしようとしたらでたエラーです。

text
1Error: crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported2 at rng (/var/task/index.js:7175:13)3 at v4 (/var/task/index.js:7209:52)4 at StandardRetryStrategy2.<anonymous> (/var/task/index.js:7327:55)5 at step (/var/task/index.js:226:25)6 at Object.next (/var/task/index.js:173:20)7 at fulfilled (/var/task/index.js:144:30)8 at processTicksAndRejections (internal/process/task_queues.js:95:5)

エラーはsrc/rng-browserから出ています。リンク先にはReactNativeの対処とかしかなくて困りました。原因は@aws-sdk/client-sqsをLayerに入れ忘れていたからでした。入れ忘れたのにrequire()ではエラーになりませんでした。入ってないならrequire()の時点で「パッケージないよ」のエラーを出してほしい……

The expected type comes from property A which is declared here on type B

aws-cdkのコードで出たTypeScriptのエラーです。例えばcoreのDurationで下のようなエラーが出ます。

text
1Type 'import("A").Duration' is not assignable to type 'import("B").Duration'.2Types have separate declarations of a private property 'amount'.

何度か遭遇しましたが、たいてい別の@aws-cdk/aws-???を入れた後に出ます。aws-cdkのパッケージたちのバージョンが揃っていないのが原因で、全部アップグレードするなどしてバージョンを揃えれば出なくなります。現状だとaws-cdkが週1回以上で更新されているので開発中に新しいパッケージを導入するときはだいたいずれます。

今回はここまで。