Using ECMAScript21 in VSCode creates syntax error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 09:21 AM - edited 11-16-2022 01:36 AM
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"
}
}
- 4,646 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 05:18 PM
It's a bit confusing, but there are two different things that can cause the error. If you're seeing an error that looks like the following it's caused by the ".eslintrc" file that ServiceNow places in the directory of your project. The error will have the red squiggly underline:
You can update the .eslintrc file so it includes es2020:
"env": {
"browser": true,
"es2020": true,
"jasmine": true
}
If you're receiving an error when you click the "Sync Project" or "Sync File" button then that's caused by the plugin. The error will show up at the bottom right of VS Code when you try to sync. It looks like the following:
For that you need to update extension.js. You update extension.js and then run the "Developer: Reload Window" command. Then you should be able to sync:
All I can think of is maybe you aren't changing the right extension.js. You can check by putting "throw Error;" at the very start of that file. By throwing an error the plugin won't load and you won't see the "Sync Project" and "Sync File" buttons. Then you know you have the right file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 12:08 AM
Cool, This worked for me. I was struggling to find a way to get rid of the linter error while using the ES6 syntax in VS code.
sync worked without any error after modifying the extension.js. My extensions.js is in this folder. ~/.vscode/extensions/servicenow.now-vscode-1.6.1/out

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 11:35 AM
Ken98, I tried your fix and it worked for me. I edited the file using Notepad++, restarted VS Code, then sync completed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 02:30 PM
Worked for me. Have my upvote. Sweet find.
--------------------------------------------------
Workflow Cowboy
LinkedIn: https://www.linkedin.com/in/dalestubblefield/
YouTube: https://www.youtube.com/@starlordnow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 11:09 AM
@ken98 in my case, it works with "es2020", but not with "es2021". This is sad, since some good features have been added to es2021, for example, logical assignment.
Is there a way to enable es2021 support?