google / protobuf.dart

Runtime library for Dart protobufs
https://pub.dev/packages/protobuf
BSD 3-Clause "New" or "Revised" License
527 stars 183 forks source link

Error: Could not resolve the package 'protoc_plugin' in 'package:protoc_plugin/protoc.dart'. #428

Open albatroz666 opened 3 years ago

albatroz666 commented 3 years ago

Tried to generated some dart code from a .proto file, got this.

Error: Could not resolve the package 'protoc_plugin' in 'package:protoc_plugin/protoc.dart'. /D:/flutter/.pub-cache/hosted/pub.dartlang.org/protoc_plugin-19.1.0/bin/protoc_plugin.dart:7:8: Error: Not found: 'package:protoc_plugin/protoc.dart' import 'package:protoc_plugin/protoc.dart'; ^ /D:/flutter/.pub-cache/hosted/pub.dartlang.org/protoc_plugin-19.1.0/bin/protoc_plugin.dart:10:3: Error: Method not found: 'CodeGenerator'. CodeGenerator(stdin, stdout).generate(); ^^^^^^^^^^^^^ --dart_out: protoc-gen-dart: Plugin failed with status code 254.

My env: protoc 3.13.0 dartsdk 2.10.2 protoc_plugin 19.1.0

I tried to launch this command: protoc --proto_path=proto --dart_out=build/gen employee.proto

Got dart bin path, protoc path and protoc_plugin in my path

BenVercammen commented 3 years ago

I've got the exact same issue as you, did you manage to find a solution?

protoc 3.14.0 dart 2.9.2 protoc_plugin 19.2.0+1

Edit: so after a good night's sleep I managed to figure it out. Turns out you need to "activate your global packages" (sorry if my terminology isn't that good, I'm an absolute pub/dart/protoc noob).

So in case you get the above error, try this:

Hope this helps! It did at least for me...

MelbourneDeveloper commented 3 years ago

I'm really struggling to get any proto to compile on Windows.

Any chance that someone from the team could work through the process on a clean Windows computer and note the issues for people setting up? There are a lot of manual aspects to this like setting up PATH etc. and it's not well documented on Windows.

This advice seemed to get me over a hump:

"activate" the protoc_plugin package using the following command: pub global activate protoc_plugin

But, when I run the command, the CLI just hangs.

BenVercammen commented 3 years ago

I agree that there is a learning curve. I'm not sure which documentation/tutorials I've used, but nowadays I don't have any issues anymore. Could you please specify the following things:

That might give a clue to what's going on...

MelbourneDeveloper commented 3 years ago

@BenVercammen I eventually got it working. It's not so much about my special case as it is that the process is very daunting and not well documented for someone on Windows. If you're trying to get this working on a clean machine there are many steps to take and you can't step through them one by one from the documentation. I'm sure I will get just as confused next time around when I format my computer or have to explain it to someone else. It's about documentation.

However, it turns out that the protoc-gen-dart batch file had an issue with it. This was the original batch file:

@echo off
rem This file was created by pub v2.13.0.
rem Package: protoc_plugin
rem Version: 20.0.0
rem Executable: protoc-gen-dart
rem Script: protoc_plugin
if exist "C:\Users\chris\AppData\Local\Pub\Cache\global_packages\protoc_plugin\bin\protoc_plugin.dart-2.13.0.snapshot" (
  dart "C:\Users\chris\AppData\Local\Pub\Cache\global_packages\protoc_plugin\bin\protoc_plugin.dart-2.13.0.snapshot" %*
  rem The VM exits with code 253 if the snapshot version is out-of-date.
  rem If it is, we need to delete it and run "pub global" manually.
  if not errorlevel 253 (
    goto error
  )
  pub global run protoc_plugin:protoc_plugin %*
) else (
  pub global run protoc_plugin:protoc_plugin %*
)
goto eof
:error
exit /b %errorlevel%
:eof

The problem was this line:

pub global run protoc_plugin:protoc_plugin %*

It needs dart. I changed it to this and now it works:

dart pub global run protoc_plugin:protoc_plugin %*

@echo off
rem This file was created by pub v2.13.0.
rem Package: protoc_plugin
rem Version: 20.0.0
rem Executable: protoc-gen-dart
rem Script: protoc_plugin
if exist "C:\Users\chris\AppData\Local\Pub\Cache\global_packages\protoc_plugin\bin\protoc_plugin.dart-2.13.0.snapshot" (
  dart "C:\Users\chris\AppData\Local\Pub\Cache\global_packages\protoc_plugin\bin\protoc_plugin.dart-2.13.0.snapshot" %*
  rem The VM exits with code 253 if the snapshot version is out-of-date.
  rem If it is, we need to delete it and run "pub global" manually.
  if not errorlevel 253 (
    goto error
  )
  dart pub global run protoc_plugin:protoc_plugin %*
) else (
  dart pub global run protoc_plugin:protoc_plugin %*
)
goto eof
:error
exit /b %errorlevel%
:eof
BenVercammen commented 3 years ago

I'm pretty sure you're not supposed to modify that file. I know I didn't, and my file doesn't have the dart command in there. What is the error you get in case you remove the dart command? My guess would be that there's something wrong with your dart or pub installation or configuration or something like that.

fdonzello commented 3 years ago

In my case, after upgrading Flutter to version 2.5.0, I needed to deactivate and reactivate again the plugin.

deakjahn commented 2 years ago

@BenVercammen Been there, done that, but no T-shirt yet. :-)

set PATH=e:\Android\protoc\bin\;e:\Android\flutter\.pub-cache\hosted\pub.dartlang.org\protoc_plugin-20.0.0\bin;e:\Android\flutter\.pub-cache\bin\;e:\Git\cmd\;%PATH%
rem call flutter pub global deactivate protoc_plugin
call flutter pub global activate protoc_plugin
protoc.exe --dart_out=./lib/gen ./protos/protos.proto

Strange, the three path items are OK, the activation is done, so it seems to be what you described, still it doesn't find its own plugin:

Error: Couldn't resolve the package 'protoc_plugin' in 'package:protoc_plugin/protoc.dart'.
../../flutter/.pub-cache/hosted/pub.dartlang.org/protoc_plugin-20.0.0/bin/protoc_plugin.dart:9:8: Error: Not found: 'package:protoc_plugin/protoc.dart'
import 'package:protoc_plugin/protoc.dart';
sigurdm commented 2 years ago

@deakjahn: I think you need the cache to point to the [...]\.pub-cache\bin not [...]\.pub-cache\hosted\pub.dartlang.org\protoc_plugin-20.0.0\bin.

Edit: sorry - I see you had that already, you probably need to remove the \.pub-cache\hosted\pub.dartlang.org\protoc_plugin-20.0.0\bin from path ....

deakjahn commented 2 years ago

I tried every combination and all failed. :-) I also tried to specify --plugin to protoc and also failed. In the end, because I happened to have a virtual Mac around, I compiled there but I'd like to be able to solve it on Windows, too.

Actually, the Mac wasn't entirely plain sailing, either, I had to tweak executable rights to files and also add a --plugin but at least it worked in the end. I wonder why this couldn't be solved in the manner of, say, flutter_launcher_icons. That also runs as a plugin, you put it under the dev_dependencies section, so it doesn't mess with the regular build process but can simply be invoked from the Flutter terminal and it just works...

sigurdm commented 2 years ago

This works for me (powershell):

> # Get protoc
> wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.1/protoc-3.19.1-win64.zip -OutFile ~\Downloads\protoc.zip 
> # Unzip it
> Expand-Archive -Path ~\Downloads\protoc.zip -DestinationPath ~\Downloads\protoc
> # Install protoc in path:
> $env:Path += ";C:\Users\sigurdm\Downloads\protoc\bin"
> # test it
> protoc --version
libprotoc 3.19.1
> # activate protoc_plugin
> dart pub global activate protoc_plugin
> dart pub global list
protoc_plugin 20.0.0
> # Test it is on path (Terminate with Ctrl+C)
> protoc-gen-dart.bat 
^CTerminate batch job (Y/N)? y
> # Install the pub global bin in path:
> $env:Path += ";C:\Users\sigurdm\AppData\Local\Pub\Cache\bin"
> # Run a compilation command
> protoc .\protos\a.proto --dart_out=.
sigurdm commented 2 years ago

dev_dependencies section, so it doesn't mess with the regular build process but can simply be invoked from the Fultter terminal and it just works...

You can do that, but it requires an intermediate step because protoc cannot take a full command as a plugin.

# Add protoc_plugin as dev-dependency
> dart pub add -dev protoc_plugin

Then make a bat file that invokes the protoc-gen-dart and use that as a --plugin.

protoc-gen-dart.bat

@echo off
dart run protoc_plugin

And then invoke like:

protoc --plugin=protoc-gen-dart.bat .\protos\a.proto --dart_out=.
deakjahn commented 2 years ago

@sigurdm Thanks, I file it away but a single run will be OK for me now. I'm not a regular user of protobuf myself but I decided to bring a seemingly abandoned plugin forward to null safety and I needed to regenerate those files with a contemporary protoc. Now that I have them, I don't probably need to do this any more in the future. I have another, even more sinister errors to deal with instead, basically the build process complains about Grade tasks that I can't see anywhere, the task name it mentions isn't even present in any of the source files. :-) (But I don't want to hijack this thread with it.)

deakjahn commented 2 years ago
  • I see you had that already, you probably need to remove the \.pub-cache\hosted\pub.dartlang.org\protoc_plugin-20.0.0\bin from path ....

No, that doesn't help. Then:

No active package protoc_plugin.
--dart_out: protoc-gen-dart: Plugin failed with status code 65.
deakjahn commented 2 years ago

Then make a bat file that invokes the protoc-gen-dart and use that as a --plugin.

protoc-gen-dart.bat

And that doesn't work, either. At first sight, you don't need to specify --plugin, it actually picks it up by name. But then, this call somehow doesn't pass the output back because protoc simply hangs. If I replace the pub run call with a simple echo, it immediately shows that the problem is with the expected return of the command:

--dart_out: protoc-gen-dart: Plugin output is unparseable:
sigurdm commented 2 years ago

Hmm, that all sounds weird.

Can you do:

echo %PATH%
deakjahn commented 2 years ago

The PATH is the same you already know (not mentioning irrelevant parts here), plus Flutter's bin. That leads us to something that might influence this: I use Flutter, not Pub and the others directly, so all my commands use flutter pub.

I now suspect the 30-years-old DOS speciality, inherited in Windows: calling batch file from batch file needs the call command, otherwise it won't return. This is different from Unix. And the callee cannot change the behavior if the caller didn't use the "proper" calling method.

So, I started to investigate what happens if, instead of a batch file, I provide a small executable (or a PowerShell script) that mimics better the Unix way of doing this. There wouldn't be any problem for me to write a small C# executable but I'd prefer the PowerShell way, if possible, for the solution to be standalone, without the need for a separate compiler for anybody trying to replicate it.

deakjahn commented 2 years ago

However, the first step fails: --plugin doesn't seem to work at all. Right now I suspect that protoc simply tries to call out for protoc-gen-dart. Windows checks the current directory before trying PATH, of course, and if it finds any of these, it will execute it:

However, if I specify anything else (say, protoc-gen-dart.ps1), ie. anything but the three extensions used for executables, it will not call that. WIndows will find the next protoc-gen-dart.* executable somewhere else along the PATH.

This unfortunately rules out PowerShell but leaves the possibility open to provide an .exe that does what we need internally, so this is the route I try now.

deakjahn commented 2 years ago

I made this quick detour but probably unnecessarily, because the problem might be one level deeper. :-)

using System;
using System.Diagnostics;
using System.Text;

namespace ProtocWrapper {
  class ProtocWrapper {
    static void Main(string[] args) {
      var process = Process.Start(new ProcessStartInfo("cmd.exe", "/c flutter pub run protoc_plugin " + string.Join(" ", args)) {
        UseShellExecute = false,
        RedirectStandardOutput = true,
        CreateNoWindow = true,
      });
      process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
      var str = new StringBuilder();
      process.OutputDataReceived += (sender, args2) => str.AppendLine(args2.Data);
      process.Start();
      process.BeginOutputReadLine();
      process.WaitForExit();
      Console.Write(str.ToString());
    }
  }
}

I don't know if you use C# but basically nothing, it starts that command line, reads the output and emits it itself. And the result is the same: nothing. It looks like flutter pub run protoc_plugin does nothing, doesn't say a word, just never returns.

deakjahn commented 2 years ago

To sum up, because it spreads many posts now:

  1. I can provide the correct PATH values, no problem with that.
  2. The preliminary steps seemed to work fine. Protoc installed, plugin installed, activated. But already a warning at activation:
Warning: Executable "protoc-gen-dart" runs "bin\protoc_plugin.dart", which was not found in protoc_plugin.
Activated protoc_plugin 20.0.0.
  1. Then, when I try to run protoc, the compiler itself works but, very likely because of the warning above, it doesn't find its plugin. The correct path doesn't help. That's why we started to experiment with the --plugin switch.

All these suggest me that we should probably return to that overlooked warning in step 2 before trying anything with step 3. That warning can't be the Right Thing. Even if it goes on saying "activated" that made me believe everything is OK in the end. :-)

sigurdm commented 2 years ago

Yeah - that warning doesn't look right!

Could you try doing a (warning: will delete all of the pub-cache)

pub cache clean

And rerunning:

dart pub global activate protoc_plugin
deakjahn commented 2 years ago

In the meantime I tried to do the same in a macOS terminal, just to compare what's left behind there, and I got the very same warning...

sigurdm commented 2 years ago

Hmm - that is even more mysterious! I get:

> dart pub global activate protoc_plugin
Package protoc_plugin is currently active at version 20.0.0.
Resolving dependencies... (1.7s)
+ _fe_analyzer_shared 22.0.0 (31.0.0 available)
+ analyzer 1.7.2 (2.8.0 available)
+ args 2.3.0
+ async 2.8.2
+ charcode 1.3.1
+ cli_util 0.3.5
+ collection 1.15.0
+ convert 3.0.1
+ crypto 3.0.1
+ dart_style 1.3.14 (2.2.0 available)
+ file 6.1.2
+ fixnum 1.0.0
+ glob 2.0.2
+ meta 1.7.0
+ package_config 2.0.2
+ path 1.8.0
+ pedantic 1.11.1 (discontinued replaced by lints)
+ protobuf 2.0.1
+ protoc_plugin 20.0.0
+ pub_semver 2.1.0
+ source_span 1.8.1
+ string_scanner 1.1.0
+ term_glyph 1.2.0
+ typed_data 1.3.0
+ watcher 1.0.1
+ yaml 3.1.0
Downloading protobuf 2.0.1...
Building package executables... (6.3s)
Built protoc_plugin:protoc_plugin_bazel.
Built protoc_plugin:protoc_plugin.
Installed executable protoc-gen-dart.
Activated protoc_plugin 20.0.0.

No warning

deakjahn commented 2 years ago

On the other hand, I adore your command. It always bugged me that my pub-cache was full of old, stale packages and sometimes I deleted a couple manually. Now I will do the spring cleaning regulary. :-)

sigurdm commented 2 years ago

The warning is written here: https://github.com/dart-lang/pub/blob/b6293b8022a2f746eb66c18d071ac0ef3a52c68a/lib/src/global_packages.dart#L718 It seems a(t least one) file is missing from your cache.

deakjahn commented 2 years ago
e:\Android\Projects\flutter_blue0\protos>call flutter pub global activate protoc_plugin
Resolving dependencies...
+ _fe_analyzer_shared 22.0.0 (31.0.0 available)
+ analyzer 1.7.2 (2.8.0 available)
+ args 2.3.0
+ async 2.8.2
+ charcode 1.3.1
+ cli_util 0.3.5
+ collection 1.15.0
+ convert 3.0.1
+ crypto 3.0.1
+ dart_style 1.3.14 (2.2.0 available)
+ file 6.1.2
+ fixnum 1.0.0
+ glob 2.0.2
+ meta 1.7.0
+ package_config 2.0.2
+ path 1.8.0
+ pedantic 1.11.1
+ protobuf 2.0.1
+ protoc_plugin 20.0.0
+ pub_semver 2.1.0
+ source_span 1.8.1
+ string_scanner 1.1.0
+ term_glyph 1.2.0
+ typed_data 1.3.0
+ watcher 1.0.1
+ yaml 3.1.0
Downloading protoc_plugin 20.0.0...
Downloading dart_style 1.3.14...
Downloading analyzer 1.7.2...
Downloading _fe_analyzer_shared 22.0.0...
Installed executable protoc-gen-dart.
Warning: Executable "protoc-gen-dart" runs "bin\protoc_plugin.dart", which was not found in protoc_plugin.
Activated protoc_plugin 20.0.0.
deakjahn commented 2 years ago

The Mac is a third variant, I have to find out how I copy-paste that here...

sigurdm commented 2 years ago

Ah - I can reproduce now! I was using a flutter installation without its own pub-cache. ... still not sure I understand what is going on - but at least I can see it happening :)

deakjahn commented 2 years ago

Mac:

Resolving dependencies...
+ _fe_analyzer_shared 22.0.0 (31.0.0 available)
+ analyzer 1.7.2 (2.8.0 available)
+ args 2.3.0
+ async 2.8.2
+ charcode 1.3.1
+ cli_util 0.3.5
+ collection 1.15.0
+ convert 3.0.1
+ crypto 3.0.1
+ dart_style 1.3.14 (2.2.0 available)
+ file 6.1.2
+ fixnum 1.0.0
+ glob 2.0.2
+ meta 1.7.0
+ package_config 2.0.2
+ path 1.8.0
+ pedantic 1.11.1
+ protobuf 2.0.1
+ protoc_plugin 20.0.0
+ pub_semver 2.1.0
+ source_span 1.8.1
+ string_scanner 1.1.0
+ term_glyph 1.2.0
+ typed_data 1.3.0
+ watcher 1.0.1
+ yaml 3.1.0
Downloading protoc_plugin 20.0.0...
Downloading protobuf 2.0.1...
Downloading dart_style 1.3.14...
Downloading analyzer 1.7.2...
Downloading _fe_analyzer_shared 22.0.0...
Installed executable protoc-gen-dart.
Warning: Executable "protoc-gen-dart" runs "bin/protoc_plugin.dart", which was not found in protoc_plugin.
Activated protoc_plugin 20.0.0.
sigurdm commented 2 years ago

In the meantime as a workaround you can (I think) delete the flutter/.pub_cache dir. That will make pub use the dart-default user-local pub cache...

deakjahn commented 2 years ago

No, I can't. Remember, I'm under Flutter, not standalone Pub. I don't have any other cache, just this one. There's nothing under my Windows home dir about .pub at all.

deakjahn commented 2 years ago

No, I lied, I do have something. Mostly empty.

Some seemingly base packages, I don't know who puts here anything, there's nothing visibly Flutter-related here.

deakjahn commented 2 years ago

Yes. I didn't delete it, but I temporarily renamed it. Now the activation ends without the warning. If I now look into the global_packages folder, the plugin gets its bin that was missing earlier under flutter. Protoc runs and the sources get rebuilt. So, you solved it temporarily but still, we would need to know why it doesn't do it automatically under flutter. :-)

I clean again and try again.

deakjahn commented 2 years ago

Can be reproduced at will. Note that it doesn't solve it in one go, it's still a convoluted process:

  1. Run the batch with flutter\pub-cache in place, with deactivate and activate. Get the warning.
  2. Run the batch with flutter\pub-cache renamed. with deactivate and activate. It gets installed.
  3. Rename it back, copy the global_packages\protoc_plugin from Pub to Flutter.
  4. Run the batch again to do the work, withouth deactivate and activate because that would ruin it again.
  5. Start again on every upgrade.
sigurdm commented 2 years ago

I have found the culprit. There was a bug in pub in how it listed files in packages. This bug has already been fixed (https://github.com/dart-lang/pub/commit/37d05928939b3100e7e55c3dff922651db1de1e1). I was lucky to be using an old flutter-checkout that I could reproduce :)

Not sure what flutter version you are using, but 2.8 stable with dart 2.15 should have this issue fixed.

deakjahn commented 2 years ago

Normally I use 2.8.0 now for my production code. But this is somebody else's plugin and I never thought of checking. It installed as dev 2.6.0-11.0.pre for me in Android Studio and I don't even know why... Dev behind stable? Upgrade doesn't bump it forward, either. (I do have two parallel Flutters, one stable, one dev, I sometimes needed the dev one, both for cutting edge new features, both to send a couple of PRs into Flutter engine earlier. I don't normally use it in day-to-day development, and certainly not for non-internal plugins).

deakjahn commented 2 years ago

But I switched to 2.8.0 now, yes, 2.15 Dart, and I still receive the same warning (just allowing it to deactivate and activate again). Curiouser and curiouser.

E:\Android\flutter\bin\flutter.bat --no-color upgrade
Flutter is already up to date on channel stable
Flutter 2.8.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision cf44000065 (5 days ago) • 2021-12-08 14:06:50 -0800
Engine • revision 40a99c5951
Tools • Dart 2.15.0
Process finished with exit code 0
sigurdm commented 2 years ago

Hmm - that sucks!

Can you attach a file (or a gist) with the full output of dart pub global activate protoc_plugin -v? Maybe I can see something fishy from the logs.

deakjahn commented 2 years ago

Sure.

activate.zip

deakjahn commented 2 years ago

I have protoc and protoc_plugin in e:\Android, although for the second I tried both inside the normal pub-cache and here, installed separately. The normal Flutter is in e:\Android\flutter, and Projects\flutter_blue0 is the actual plugin where I try to activate, generate, whatever. This is the dir I launched the batch from.

sigurdm commented 2 years ago

Yeah - my focus is on why pub cannot see the binary inside the package, even in version 2.15...

Not sure I'll get to the bottom of this right now.

The-Funk commented 2 years ago

Just chiming in. I had the exact same issue as being described here. That warning mentioned above appears to be the cause.

I am on Dart 2.15 and Flutter 2.8 on Windows x86_64

I can verify that under the hosted section of the flutter pub cache, the bin directory and the protoc_plugin.dart do exist.

This is the path I have for that.

C:\Users\TheFunk\AppData\Local\Android\flutter\.pub-cache\hosted\pub.dartlang.org\protoc_plugin-20.0.0\bin

Interestingly, I was able to resolve this by doing a

dart pub global activate protoc_plugin

instead of a

flutter pub global activate protoc_plugin

To be very explicit about the things I tried (was throwing things at the wall)

Hopefully this is of some help.

wwwqyhme commented 2 years ago

i'm trying to build my own dart pad , i faced same issue and resolved ,thanks everyone that comment on this issue

dhruv1294 commented 2 years ago

I faced the same issue after upgrading flutter to the latest version, thank you for the comments

13wis commented 2 years ago

Just chiming in. I had the exact same issue as being described here. That warning mentioned above appears to be the cause.

I am on Dart 2.15 and Flutter 2.8 on Windows x86_64

I can verify that under the hosted section of the flutter pub cache, the bin directory and the protoc_plugin.dart do exist.

This is the path I have for that.

C:\Users\TheFunk\AppData\Local\Android\flutter\.pub-cache\hosted\pub.dartlang.org\protoc_plugin-20.0.0\bin

Interestingly, I was able to resolve this by doing a

dart pub global activate protoc_plugin

instead of a

flutter pub global activate protoc_plugin

To be very explicit about the things I tried (was throwing things at the wall)

  • Copied bin directory from hosted protoc_plugin to global_packages protoc_plugin directory (thought maybe it was looking in the global packages directory for the bin folder, pretty sure I was wrong and that didn't do anything to help)
  • Added the protoc_plugin-20.0.0 directory to my path (I don't think that helped)
  • flutter pub global deactivate protoc_plugin
  • flutter pub global activate protoc_plugin (saw error message, thought, why not try pub command with dart)
  • dart pub global activate protoc_plugin
  • Run protoc command without --plugin directive
  • Profit

Hopefully this is of some help.

For some reason this resolved the issue. I am also on the latest version of flutter

Farley-Chen commented 10 months ago

这对我有用(powershell):

> # Get protoc
> wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.1/protoc-3.19.1-win64.zip -OutFile ~\Downloads\protoc.zip 
> # Unzip it
> Expand-Archive -Path ~\Downloads\protoc.zip -DestinationPath ~\Downloads\protoc
> # Install protoc in path:
> $env:Path += ";C:\Users\sigurdm\Downloads\protoc\bin"
> # test it
> protoc --version
libprotoc 3.19.1
> # activate protoc_plugin
> dart pub global activate protoc_plugin
> dart pub global list
protoc_plugin 20.0.0
> # Test it is on path (Terminate with Ctrl+C)
> protoc-gen-dart.bat 
^CTerminate batch job (Y/N)? y
> # Install the pub global bin in path:
> $env:Path += ";C:\Users\sigurdm\AppData\Local\Pub\Cache\bin"
> # Run a compilation command
> protoc .\protos\a.proto --dart_out=.

Thanks, it helps me, I found myself with the wrong cache/bin path

LouisLou2 commented 6 months ago

Another way: just compile the protoc_plugin.dart into an exe(like the way we complie any normal dart source).The generated executable does not require a dart executable to run. You should copy the generated executable protoc_plugin/bin/protoc_plugin.exe to your PATH with name protoc-gen-dart, or pass the path to it to protoc's --plugin option when invoking protoc.