Import third party module in ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2018 03:29 AM
Hi guys,
I've been trying to import a npm module in ServiceNow - Babel. Now the module works perfectly on V8, as well as Mozzila's and IE's JS engines (tested in browser console), give no errors and I can pretty much use the Babel API in the browser. Now, when I try to create a script include and paste the module code (either from the whole file, from the minified file or its browser-standalone) I get two syntax errors (1 is on babel, the other one is on browser standalone):
Could not save record because of a compile error: JavaScript parse error at line (16) column (7511) problem = missing } after property list (<refname>; line 16)
and
Could not save record because of a compile error: JavaScript parse error at line (1) column (550) problem = missing name after . operator (<refname>; line 1)
When working with the full version of the modules I looked into the script, but the syntax was not wrong on the indicated lines. Furthermore, I tried pasting the modules in a background script and call some of the functions (much like I did in the browsers consoles), I still got the same errors (except that the full versions would just render the 'The connection was reset' page in the iframe).
The module itself is written in es5, current ServiceNow JS version, so there is no incompatibility between the JS versions, just Rhino acting weird and failing to compile the module. Are there any workarounds from this, or at least any alternatives to Babel that I can import in ServiceNow. I'm not looking to transpile and pipe my local code to a ServiceNow instance, what I basically need is a function that takes a string parameter (js code in text) and returns a string with the transpiled js (to es5).
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2018 04:41 AM
Unfortunately not directly a solution, but I encountered the same problem. I found that in my case the compile error:
Could not save record because of a compile error: JavaScript parse error at line (X) column (YYY) problem = missing name after . operator (<refname>; line X)
occurs from the fact that the script code is using variable names that ServiceNow considers "keywords", this should work fine since the entire library is in an IIFE. I could not find a specific BR, but i was wondering if here maybe is a way to disable the compile check completely?