When using sweetalert (or any 3rd party library) y...
# suitescript
g
When using sweetalert (or any 3rd party library) you just add the min.js file as a custom module? SetTimeout is giving me an error
Copy code
Fail to evaluate script: org.mozilla.javascript.EcmaError: ReferenceError: "setTimeout" is not defined. (/SuiteScripts/Modules/sweetalert.min.js#1)
When trying to save the script. I do not even have my script using it yet...
b
netsuite evaluates libraries so that it can do things like detect entrypoints
this is done serverside, so those client libraries dont have access to browser globals
i usually use the local require in the relevant entry point code to get around it, you can also use the global require function if you dont care about relative paths
g
thanks! going to try this
do i need to implicitly tell it to use AMD
b
huh
g
all i should have to do is var Swal = require('SuiteScripts/Modules/sweetalert.min.js') in the function that is using SWAL
d
@battk for the link you posted, have you had success with the inline CommonJS style they showed in (serverside) SuiteScripts? maybe I am doing something wrong but I could never get that to work, in my experience always needed to be the require with dependencies[] & callback style
b
simplified CommonJS wrapping, its equivalent to to putting the dependency in the define
you must use the callback style require in your entry point
d
hmm this does not seem to work for me I either get _"Module name _ has not been loaded yet for context: . Use require([])" or _"Module name _has not been loaded yet for context: /SuiteScripts/pathto/scriptFile.js","requireType":"notloaded"}
b
What code are you trying
d
interesting, it seems to only work for the second variation on https://github.com/amdjs/amdjs-api/blob/master/require.md#local-vs-global-require- no ['require'] even though the doc makes it seem like those are equivalent?
in any case, how would you do something like
Copy code
define(['N/record'],function (record, require) { 
...
var test1 = require('./testmod1')
...
})
then? appears
require
then becomes undefined
b
Copy code
define(["N/record", "require"], function (record, localRequire) {
  localRequire(["./testmod1"], function (testmod1) {});
});
d
@battk I am saying though in combination with prior statement, like having the ["require"] at all gives me the "Module has not been loaded yet for context" error, so only seems to work when I have as style
Copy code
define(function (require) { ...
like I am also desiring/expecting to be able to use
var test1 = require('./testmod1')
inline somehow as well, maybe that particular combination of everything is not possible. Edit : Ah ok maybe just cant mix and match ... just having
var record = require('N/record')
as well seems to give me what I am looking for :)