I’m trying to use a npm package to implement some openssl functionality. I requested installation of npm package openssl-nodejs and it seems to now be installed
So as per the readme for the package I added this to my backend code:
const openssl = require ( ‘openssl-nodejs’ )
But when I try to preview or publish and view the page I get the error.
You say that you added it to backend code, yet you get the error “on the page”. I get the same error when I import on a page. This library can only be used in backend (nodejs) code (.js or .jsw file).
@bwprado
We are not just learning new things. Because of JS’s large scope of “learning-material”, sometimes already learned lessons → gets into oblivion.
And it’s good to refresh them, by reading (normaly) already known stuff.
@yisrael-wix , Thanks for responding. I actually tried it in the front end page and backend code file (I read somewhere Wix did support importing npm packages in the frontend now) and just included the front end screenshot accidentally, but the backend error is similar, see below. This error occurs when I call a function from the frontend page that’s in the backend code file.
Bruno, thanks for the info. Did you try it with the openssl-nodejs package specifically? I saw you responded to Yisrael’s suggestion about only using it in the backend, but I did try that and still get the same “Cannot find module” error. But maybe it’s a problem with this specific package and I can look for another one with the same functionality that might work.
@russian-dima No, not yet. I still have the issue when using the module in the backend. I’m considering requesting another openssl package installation from wix, but I’d like to be sure it’s not just an issue with my code before I go that route. And the only reference to the openssl module I have in the backend code file right now is:
@russian-dima THANKS! That is extremely helpful if also confusing (since it looks like you did exactly what I did). That def gets me on the right track to do some more testing and at least know it’s not a problem with the package. Really appreciate you taking the time. Guess first thing I’ll do is start with a blank backend file and see what happens when I import. I’ll update this thread when/if I figure it out in case someone else ever runs into the same issue.
@russian-dima so i created a new backend file and page, and like you I didn’t get the error initially with the import statement, but when I added a dummy test multiplication function and called that from the front end page it still throws the module not found error. I’m guessing you weren’t seeing the error because you didn’t call anything that loaded the backend file when you did the preview.