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,637 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 12:07 AM
Did you manager to find a solution to this? I'm experiencing same issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2023 02:32 AM
No, unfortunately. This is still a problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 12:32 PM
It's due to the ESLint configuration that runs before a file is synced. I can see the ESLINT config code here from the plugin. It's configured to not use .eslintrc. By default ESLINT is only configured to support ES5:
u = new(0, r.CLIEngine)({
envs: ["browser", "mocha"],
useEslintrc: !1
});
The ESLint configuration for the CLIEngine the plugin is using is only configured for ES5, so we need to either be able to specify an ESLint config file, or have that configuration changed to something like below where I've added es2020 to the list of envs:
u = new(0, r.CLIEngine)({
envs: ["es2020", "browser", "mocha"],
useEslintrc: !1
});
I've made that update locally to my own version of the plugin and it fixes the problem. 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.
If you want to make this change yourself you'll have to find the plugin code on your machine. I'm using a Windows machine and the plugin code is located at: ${USERPROFILE}/.vscode/extensions/servicenow.now-vscode-1.5.0/out/extension.js
The code is minified. It's easiest to find the part you'll need to update by searching for the string "r.CLIEngine". Then you modify the envs array by adding "es2020" and save the file. Use a plain text editor to do this as the file is very large. If you try to use VS Code it will probably choke on the file due to the size.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 11:50 AM
@ken98 I tried your fix and it didn't work for me. The logic seems sound, so maybe I'm missing something. I attempted to sync after each of the following: editing the extension.js file as described, closing/opening VSCode, resetting the ServiceNow project, and disabling/re-enabling the ServiceNow extension. My thinking was that the 'fix' may not have been loading into the extension on file save. But even after all that, I still get the parsing error saying "let" is reserved.
Any extra advice?