Hey! What's the best way to reference other JS fil...
# suitescript
e
Hey! What's the best way to reference other JS files from a SuiteScript? I currently have an issue where I have a set of JS files that make of my SuiteBundle. When I install the said SuiteBundle into my production account everything goes well, the files can be references as expected and everything ends up in
SuiteScripts/
. When another account (unrelated to mine) installs the same SuiteBundle it ends up in
SuiteBundles/
with the Bundle ID as the folder name and when the scripts are running they are failing to find the JS files being referenced. Like the following
Copy code
Installation Script Error

MODULE_DOES_NOT_EXIST

{"type":"error.SuiteScriptModuleLoaderError","name":"MODULE_DOES_NOT_EXIST","message":"Module does not exist: /SuiteBundles/mylibrary.js","stack":[]}
What I'm doing wrong here and why does the install differ between production environments in terms of where it gets installed?
s
just use relative links instead of the full path... things in the same folder as the current file can be referenced like
./mylibrary
if you need to go up a directory and go down into another folder do like
../someOtherFolder/mylibrary
e
Thanks for the reply! I should have mentioned that I'm using relative paths. So this specific error message is referenced in the following way
../mylibrary.js
.
Worth mentioning is the script is a
bundleinstallationscript
, so maybe that's a problem? That it's running outside the directory context?
s
Ya i've personally never tried to reference another js file in a bundle install script
e
Alright, I'll try not using references in that file. But keep the rest. Thanks! 🙌
Seems like the
bundleinstallationscript
worked fine now, but the rest of the scripts had the same problem now. So I seem to have issues referencing files. Even though I'm doing it relatively like mentioned above 🤔
e
It's been a long time since I worked with a bundle, but I believe you have to reference their files differently
I wouldn't really expect that to be necessary within the bundle itself, but might be worth investigating
The rest of that article is worth perusing as well just to confirm your current approach
e
Thanks! It's a bit weird to reference the Bundle ID in the path, because you only know that after having created the Bundle. So that would mean the follow steps would have to be made? 1. Create a bundle with my files 2. Edit my files with the Bundle ID in the paths 3. Update the bundle so it has the latest files
e
Hence my comment that I wouldn't expect that style to be necessary within the bundle itself, but thought it bore consideration
e
Yeah, I eventually just gave up and stopped referencing the files. But it's something I want do in the long run for sure. The main issue I have with it at this point is that I can't test it properly. I didn't have this issue when installing the Bundle into my production account. But for another production account I did. For my account the contents of the Bundle was installed in
SuiteScripts/
and for the other account it was installed under
SuiteBundles/
. I'm assuming this is happening because my production account is technically the owner of the bundle, but not sure 🤷
m
My experience is that I couldn't reference other script files from the bundle installation script. Consider the first time the bundle is installed. My assumption is because one of the entry points of bundle installation scripts is
beforeInstall
and when NetSuite tries to load your script to execute this entry point, it would also try to load any referenced module files. This didn't seem to work because those module files haven't been installed yet.
e
That's how I would resonate I as well. My Bundle installation script only contains an
afterInstall
though, by then everything should be "in place" in my opinion. But it doesn't look it.