How to fix NanoPB MyProtocol.proto: Option “(nanopb)” unknown.

Problem:

When trying to compile a project using NanoPB, you see a warning like

MyProtocol.proto:11:27: Option "(nanopb)" unknown. Ensure that your proto definition file imports the proto which defines the option.

Solution:

At the top of the .proto file mentioned in the warning message, just after syntax = "proto3"; add the following line:

import "nanopb.proto";

After that, the error should be gone.