Standalone module works with imported script but not when included in an app

I have a module that imports a crypto (crypto-js) library at the module level (3 dot menu > Scripts and style > Add new). When testing the module alone it works perfectly fine. When I include this module into an app it no longer works.

It doesn't reference any external info and all the data within the module is accessible. I know it has to do with the library because I'm using the crypto library to hash values and I can display the values I'm hashing just fine, but once I wrap it in the hash function it no longer work in the app (again, it works in the module though).

Is there some security setting preventing a module preloaded library from working in an app? When I add the library at the app level it doesn't work either though. Does it need to be added at the organization level? What else could be the issue here?

Anyone else run into something similar?

Hi there @hanni :wave:

So it turns out that this is a known thing that we're tracking right now. Unfortunately custom CSS or imported JS imported from a module may sometimes not be carried over to the parent.

Your best bet would be to add it to the organization or app level.

1 Like

Thanks for the response @Pawan. I've tried that as well but unfortunately no luck there either. I wonder if there's also the opposite issue where the module doesn't have access to the app level imported library.

Hi @hanni

Are you able to set that up at the org level? I'm wondering if that'll do it there

Just tested this and that doesn't work either. Still only works as a standalone module.

Hi there :wave:

When you mention it doesn't work, what does that mean really? Are you seeing any particular error messages? What functionality isn't working that you'd like to get going there?

I have a function that hashes a value and returns it. When I check the value in the module (by sending to an Output), it returns the hash as expected. When I check the Output in the app it returns null because the crypto library used to hash is not available. If I edit the single line that's using the hash function from the crypto library to not hash, then I see the Output value in the app.

Hi there :wave:

I went on ahead and did some of the leg work on my end and was able to get that library loaded into a module and the output of it be displayed in an app of mine. See the following screenshot of it working well:

I wanted to ask how you're importing this library in the first place? Also, how're you setting your output? Can you share a screenshot of where you loaded this library as well as a screenshot of you setting up your module's output?

I'm adding the library through Menu > Scripts and Styles > Libraries

Here you can see it's working as intended within the module:

But when I view the output in the app (using all the same info in the module), it gives me null:

However, if I keep everything the same and just don't use the library (don't use the hash() function) then the value gets passed through to the output in the app:


So from this it's pretty clear that it's an issue with the hash() function, and since it works in the module and not the app it's clear the library is getting blocked for whatever reason.

As suggested, I've tried adding the library at both the app and organizational level and neither worked, it was the same results with both.

Hi @hanni :wave:

Oh boy that is strange indeed. What specific function from the library are you calling. In my previous example I used something like:

CryptoJS.MD5("Message")

sigh

Well that's embarrassing. You made me realize I also added this under Scripts and Styles > Javascript:

function hash(msg) {
	return String(CryptoJS.MD5(msg));
}

It now works! I would still argue that the Javascript snippets entered there should be carried over, but at least I'm able to move forward now. Thanks for the persistence @Pawan!

Happens to the best of us my friend :sweat_smile: I'm glad you were able to get that going!