Share code between pieces

Hi,

I’m facing an issue using a local piece (not yet published in the npm registry).

I have two pieces that use the same code to make some http requests. To share the code I created a new piece with the common code. As you have in ‘@activepieces/common’ but when loading the pieces I am receiving this error: ‘ERROR: Cannot find module’.

The error occurs in the ‘loadPieceFromFolder’ function when trying to import, but all the pieces are in the dist folder. Am I missing something?

Best regards,
Marcelo Gonçalves

1 Like

That seems correct, can you open a draft pr or a place on github where i can check the codeout and try it?

Hi,

I created a very simple example in this branch: GitHub - MarceloRGonc/activepieces at common-piece

So, we have a new piece ‘pieces-validator’ with shared code that is used in the pieces ‘sendy’ and ‘invoiceninja’. When loading the pieces in the ‘locadPieceFromFolder’ method in the ‘file-piece-metadata-service’ file, the ‘invoiceninja’ piece fails with this error ‘ERROR: Cannot find module’ when calling the ‘importFresh’ method.

Basically what I discovered is that we are not able to import a new local piece into the ‘index.ts’ of another piece.

I think in that case you have a new package. We do perform linking for the local environment, as these packages are not available in npm. The pnpm tries to download them from the internet, but they don’t exist. So, you have to explicitly do the linking in the local environment

Thanks. Linking the package in the local environment worked.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.