Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Using ECMAScript21 in VSCode creates syntax error

Karl Martin Lun
Tera Contributor

I was very exited to get started with development with modern Javascript, so I changed the settings in my scoped app and rewrote my application to it.

 

 

let MyClass = Class.create();
MyClass = class {
    constructor() {}
}

 

 

I've written a class in a Script Include with this format in ServiceNow Studio everything working.

When importing the app to Visual Studio Code (VSCode), trying to sync the same Script include I get this error:

 

 

Syntax errors detected in PartyRegisterApi.script.js -> Parsing error: The keyword 'let' is reserved

 

 

I have tried changing the .eslintrc-file and package.json to no success. The contents of those files are pasted beneath.
Can anyone please help?

 

 

package.json (in this file I've tried several eslint-values)
{
  "name": "now",
  "version": "1.0.0",
  "dependencies": {
    "eslint": "8.27.0"
  }
}
.eslintrc (this is not the original content, but what I found in the sys_property glide.ui.syntax_editor.linter.eslint_config)
{
  "parserOptions": {
    "ecmaVersion": 12
  },
  "rules": {
    "sn-no-async-await": "error",
    "sn-no-generator-functions": "error",
    "sn-no-promises": "warn",
    "sn-no-proxies": "warn",
    "constructor-super": "warn",
    "no-case-declarations": "warn",
    "no-class-assign": "warn",
    "no-compare-neg-zero": "warn",
    "no-cond-assign": "warn",
    "no-console": "warn",
    "no-const-assign": "warn",
    "no-constant-condition": "warn",
    "no-control-regex": "warn",
    "no-debugger": "warn",
    "no-delete-var": "warn",
    "no-dupe-args": "warn",
    "no-dupe-class-members": "warn",
    "no-dupe-keys": "warn",
    "no-duplicate-case": "warn",
    "no-empty-character-class": "warn",
    "no-empty-pattern": "warn",
    "no-empty": ["warn", { "allowEmptyCatch": true }],
    "no-ex-assign": "warn",
    "no-extra-boolean-cast": "warn",
    "no-extra-semi": "warn",
    "semi" : "warn",
    "no-fallthrough": "warn",
    "no-func-assign": "warn",
    "no-global-assign": "warn",
    "no-inner-declarations": "warn",
    "no-invalid-regexp": "warn",
    "no-irregular-whitespace": "warn",
    "no-mixed-spaces-and-tabs": "warn",
    "no-new-symbol": "warn",
    "no-obj-calls": "warn",
    "no-octal": "warn",
    "no-redeclare": "warn",
    "no-regex-spaces": "warn",
    "no-self-assign": "warn",
    "no-sparse-arrays": "warn",
    "no-this-before-super": "warn",
    "no-undef": "off",
    "no-unexpected-multiline": "warn",
    "no-unreachable": "warn",
    "no-unsafe-finally": "warn",
    "no-unsafe-negation": "warn",
    "no-unused-labels": "warn",
    "no-unused-vars": "off",
    "no-useless-escape": "warn",
    "require-yield": "warn",
    "use-isnan": "warn",
    "valid-typeof": "warn"
  }
}

 

 

18 REPLIES 18




I'd like ServiceNow to open source the plugin so we could make updates.  It's not fun looking through minified code to find a problem.

I strongly agree with this, but for the time being it would also be sufficient if the extension was just updated to use the project's local .eslintrc file instead. This way, we could enforce valid syntax and other rules on a per-project basis.

 

If I go out of my way to modify the config, then ServiceNow should believe that I know what I'm doing.

Seconding that this worked for me. I was trying to use some "const" and arrow function (=>) for each loops, and making this quick change resolved my issue, letting me sync again.
Hope ServiceNow can make this fix so this is more usable with the new language features.

nilshaug
Tera Contributor

@Servicenow_1 when will you update the VS-Code Plugin? There are a bunch of updates neccessary!

JoseI1156258720
Tera Contributor

Gemini give a summary of the fix, it works for es2021, I tested for "Template Literals".

 

Gemini fix:

The "Nuclear Option" (Hacking the Extension)

If the two steps above don't work, it’s because the extension's internal "Sync" logic is ignoring your config. There is a well-known community fix that involves editing the extension's source code directly:

  1. Locate your extension folder:

    • Windows: %USERPROFILE%\.vscode\extensions\servicenow.now-vscode-x.x.x\out\

    • Mac/Linux: ~/.vscode/extensions/servicenow.now-vscode-x.x.x/out/

  2. Open extension.js in a text editor (it will be minified and huge).

  3. Search for the string: r.CLIEngine

  4. Look for the envs array nearby. It usually looks like envs: ["browser", "mocha"].

  5. Add "es2021" to that list: envs: ["es2021", "browser", "mocha"].

  6. Save and restart VS Code.