Hello, I a trying to load AMD library with SS 2.1 ...
# suitescript
h
Hello, I a trying to load AMD library with SS 2.1 and I am getting back an error saying lib object in not a constructor, other AMD compatible libraries like lodash load up properly. Anyone have any ideas?
s
is the error happening while loading the lib, or not until you try to use the lib? Also, would be helpful to know what lib it is - maybe it's something with a known problem and/or workaround for use in NS?
h
the error is happening when I i try to create instance of lib I an trying to use. the lib is AMD compatible. Plus i am able to load lodash successfully and use it in the same script
I think I need to do something as suggested on page 24/25 but its not very clear to me
The error I am specifically getting is obj is not constructor
s
that's a very generic error message - would likely need to see code to resolve
if the library you're using is meant to work in a variety of module environments (AMD, UMD, CommonJS, etc) then it may be that it's being fooled into thinking it's something other than AMD when running in netsuite.
otherwise, you should share the syntax you're using. from the PDF you linked it looks like they were demonstrating using default exports from the modules.
maybe you need to explicitly import , or use
import * as foolib from "foolib"
sort of syntax
h
When I used require instead of define to load the module it worked..
Thanks @stalbert for your help
s
👍 though you shouldn't need to use
require()
unless you're 1. working in the browser console for testing or something or 2. you really need to dynamically load the lib. You should generally be able to list any well behaved AMD module as a dependency in your define() definition (or just use
import
syntax if using TypeScript)
d
I asked the same question a few months ago to @Albert Margarit (NS Eng Lead) and the consensus was the ES6
import/export
syntax was not yet supported in 2.1 , but maybe this has changed?
s
when I refer to
import
syntax I mean transpiling TypeScript. Personally I use UMD as the target output for TypeScript so I can run the same code in NetSuite or in NodeJs (for unit tests)
at the moment, when I build scripts for SS2.1 I'm targeting ES2018 as the JS version but UMD as the module format.
seems to work like a charm.
a
@dbarnett You are right. ES import/export syntax is not supported in 2.1 yet.