Cannot find module error

Note: I’m both a JavaScript and Wix newbie.

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.


I also tried
import openssl from ‘openssl-nodejs’
with the same result.

Any help is much appreciated. Thanks.

Hmm, not sure, but it looks like you typed openss1… instead of openssl…

1 Like

I got the same error as yours… I thinks it is a WIX Package problem.

2 Likes

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).

2 Likes

Every day I learn something new! It’s amazing.

2 Likes

@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.

It happens often to me, too.

2 Likes

@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.

I actually thought the same thing but it’s just the font is weird. I double checks and it’s SSL.

Yeah, it occurred to me also, but only after I had posted. Thx for responding.

1 Like

@francis72306 Already resolved here ?

@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:

const openssl = require ( ‘openssl-nodejs’ );

@francis72306
I just did some quick testing!

  1. Installed…


2) Addded the import onto my backend…

  1. No ERRORS in PREVIEW-MODE !!!


4) No ERRORS on published site…


Both versions of imports working…
1)

import {openssl} from 'openssl-nodejs'
const openssl = require('openssl-nodejs')
1 Like

@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.

1 Like

@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.

Backend code:

Frontend code:

Error in Preview:

@francis72306 You are right! → Seems to be a broken npm-package.

1 Like

Perhaps some UPDATES here!
Read this post, your issue could be affected (or even already resolved), too.

1 Like