Libraries that use fs, assert and util

Hi,
I’m making an extension that would use a library that does interfaces -> JSON Schema transformation. The specific library is https://www.npmjs.com/package/ts-json-schema-generator, however I’m getting several errors regarding fs, assert and util. “Can’t resolve fs in /…” is the kind of error I get when running yarn.

I’m wondering what would be the solution for this. I’s it because I’m using the library in the frontend-module, or should I do the transformation somehow in the backend to utilize node libraries.

Thanks in advance

@loba thank you for the discussion, as you pointed out the frontend (browser) cannot use Node APIs directly, they can only be used in the backend (node).

For more information you can look at the code organization documentation which provides some additional details.

Thanks for the answer! So if I understood correctly, a way to use the library I mentioned before, would be to:

  • Pass the desired parameter to the backend (this case it could just be a string).
  • Use the library tools in the backend
  • Send the processed result back to the frontend

Should the messaging between front and backends be done with the JSON-RPC, or am I mistaken?

@loba frontend and backend communication is done with JSON-RPC correct, you can take a look at backend communication template from https://github.com/eclipse-theia/generator-theia-extension.

Please note you do not need to use fs directly, you can use our FileService (which can be used in the frontend):

Okay, I will try it with this. Thanks.