Open jens-ghc opened 1 year ago
This issue appears to be a bug in the current version of flatc that affects TypeScript output when using three or more levels of namespacing.
As a workaround, you can manually adjust the test.ts file to use the correct relative path for the Person module. In your example, you can change the export statement in test.ts from:
javascript Copy code export { Person } from './company/test/person.js'; to:
javascript Copy code export { Person } from './test/person.js'; Alternatively, you can use a different tool to generate TypeScript code from your FlatBuffers schema, such as flatbuffers-ts, which is a third-party TypeScript code generator for FlatBuffers that supports multiple levels of namespacing. To use flatbuffers-ts, you can install it via npm:
Copy code npm install flatbuffers-ts And then generate TypeScript code from your schema file using the flatbuffers-ts command:
Copy code flatbuffers-ts person.fbs This should generate TypeScript code with the correct relative paths for the Person module, even with three or more levels of namespacing.
not using
I am getting the same issue with flatc 23.5.26. I've resorted to using sed to remove the extra toplevel folder in the export paths, but it would be nice to see this issue get fixed.
Can this that issue https://github.com/google/flatbuffers/issues/7828 be related to this one ? It has been closed without any review but it feels like it is close to the same problem
This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale
, or this will be closed in 14 days.
This bug is still present. I have to manually replace the paths with the correct relative paths each time.
Yes, same for me. It's pretty disruptive as we have to do the adjustment every single time in a couple of files when we regenerate the flatbuffers. Would be great if this could be fixed.
Using flatc version 23.3.3 and compiling to Typescript:
I'm running into an issue where using 3 levels of namespacing in the flatbuffer file (e.g. com.company.test) produces an export file named
tests.ts
which references other files using a wrong relative path.For example, here's the content of
person.fbs
when running
it produces this directory structure:
The content of
test.ts
isWhen compiling file
test.ts
in typescript, I get this error:This seems to be caused by
test.ts
using the wrong relative path. When I manually change the path intest.ts
to./test/person.js
it compiles fine.This issue only happens when I use 3 namespace levels. If I use 2 levels, then the relative path in test.ts are correct. E.g. this will produce a correct file that compiles just fine in typescript:
I tried any of the typescript related compiler flags for
flatc
but none of them made a difference. How can I get the relative paths to be produced correctly?