1
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?

More than 1 year has passed since last update.

「timestamp.proto: File not found.」「Import "timestamp.proto" was not found or had errors.」というエラーが出る件

Last updated at Posted at 2024-03-21

gRPCを実装する際に以下のようなuser.protoファイルを作成しました。そして、protocコマンドを実行したところ、以下のようなエラーが出ました。解決法を紹介します。

user.proto
syntax = "proto3";

package pb;

import "google/protobuf/timestamp.proto";

option go_package = "./pb";

message User {
    string name = 1;
    google.protobuf.Timestamp updated_at = 2;
    google.protobuf.Timestamp created_at = 3;
}

エラー文
timestamp.proto: File not found.
user.proto:5:1: Import "timestamp.proto" was not found or had errors.
user.proto:11:5: "google.protobuf.Timestamp" is not defined.
user.proto:12:5: "google.protobuf.Timestamp" is not defined.

解決法

こちらに解決法が記載されていました。
https://github.com/protocolbuffers/protobuf/issues/5131

具体的には以下のコマンド実行します。

apk add protobuf-dev

私の場合はDockerを用いて開発を行っていたのでDockerfileに以下の処理を追加しました。

Dockerfile
・
・
RUN apk add protobuf-dev
・
・
1
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
1
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?