Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The import is not working #838

Closed
jack-theripper opened this issue May 12, 2024 · 2 comments
Closed

The import is not working #838

jack-theripper opened this issue May 12, 2024 · 2 comments

Comments

@jack-theripper
Copy link

Generates incorrect import code when

version: v1
plugins:
  - plugin: es
    opt: target=ts
    out: src/protobuf

Error: Cannot find module './packet_pb.js'

// packet9999_pb.ts:

import type { GenDescFile, GenDescMessage } from "@bufbuild/protobuf/codegenv1";
import { fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv1";
import type { Packet } from "./packet_pb.js";
import { fileDesc_packet } from "./packet_pb.js";
import type { Message } from "@bufbuild/protobuf";
import "packet.proto";

message Packet9999 {
	required int32 packet_id = 1;
	required MSG1 val = 2;
// ...
}
@srikrsna-buf
Copy link
Member

It could be because of the .js extension. We generate .js as described in the ECMAScript spec. But bundlers haven't yet implemented it. You can use the import_extension option to remove the extension:

version: v1
plugins:
  - plugin: es
    opt: target=ts,import_extension=none
    out: src/protobuf

If the import is coming from a buf module dependency, then you may need to run use the --include-imports flag

@felixangell
Copy link

@srikrsna-buf this is exactly it for me. the files generate as '.ts' but the import path resolves to '.js'. your fix worked - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants