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

capnp_ts_src_serialization_message__WEBPACK_IMPORTED_MODULE_1__.Message is not a constructor #168

Open
lsvb30 opened this issue Jan 19, 2022 · 0 comments

Comments

@lsvb30
Copy link

lsvb30 commented Jan 19, 2022

Hi
I installed capnp-ts in my visual studio 2022 angular12 project.

when I simply want to use "new capnp.Message()" method as in its documentation, it raises this error on browser:

TypeError: capnp_ts_src_serialization_message__WEBPACK_IMPORTED_MODULE_1__.Message is not a constructor

The code is just like github readme file:
import * as capnp from "capnp-ts";

import { MyStruct } from "./myschema.capnp.js";

export function loadMessage(buffer: ArrayBuffer): MyStruct {
const message = new capnp.Message(buffer);

return message.getRoot(MyStruct);
}

But inside the Message.ts file, it has a normal constructor :
https://github.com/jdiaz5513/capnp-ts/blob/master/packages/capnp-ts/src/serialization/message.ts

There is no problems while writing or compiling in visual studio. It shows the constructor's arguments too.

I saw many pages about the solution of the "TypeError: ... is not a constructor" error (like changing the import line, changing source, etc) but none of them helps about this!

The other classes in the project and capnproto objects have not this problem and I'm using them as normal with "new" construction.

So what's the problem with Message.ts file?!

Update:

I checked another way of changing import line now. I used this for import a message:

const Message = require('capnp-ts/src/serialization/message.js').Message;

and used "new Message()" instead of "new capnp.Message()"

But that solves the problem for the Message class itself and there are many classes inside project like that, need similar changes!

So it raises now a new error inside the message.js file:

TypeError: arena_1.SingleSegmentArena is not a constructor

And if I solve it there will be another one :D

So I know the problem is in the generated js files, and the problem may be resolved by changing entire capnp-ts module, but why all this incompatibility happened?! And how can I fix it without changing module source files?!

I reinstalled the module via npm but nothing changed.

Stackoverflow link for this question:
https://stackoverflow.com/questions/70764851

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

1 participant