【Strapi】Error creating endpoint xxx xxx Cannot read properties of undefined (reading xxx)

こんにちは、フリーランスエンジニアの太田雅昭です。

今回、表題のようなエラーが出まして、さっぱり分からずエラー内容で検索してみたら、ぴったりな記事を見つけました。

Error when trying to create a simple custom route: Error creating endpoint GET : Cannot read property of undefined

System Information Strapi Version: V4 Operating System: aws linux AMI Database: mysql Node Version: 14.18.1 NPM Version: 6.14.15 I am trying to get the example code from the docs “Development/Back-end customization” to run for a simple custom route “/api/customizeUser/…”.

通常、以下のような構成になります。

custom-xxx
 ┗ controllers
    ┗ custom-xxx.ts
 ┗ documentation
    ┗ 1.0.0
       ┗ custom-xxx.json
 ┗ routes
    ┗ custom-xxx.ts
 ┗ services
    ┗ custom-xxx.ts

結論としましては、カスタムAPIのファイル名に、大文字やアンダーバーを使ってはいけないとのことです。キャメルケースもスネークケースもダメで、ケバブケースでやれとのことですね。いやいや、誰が気づくねんこんな仕様。リンク先で教えてくださっている方は、すごい。

ではでは。