cactbot: Bug: ESLint doesn't run properly in VSCode
Desctiption
After #2567 landed, when I am using VSCode opening up cactbot repo, ESLint didn’t work always.
When I look at Output window and select ESLint, then I saw the error stack looks like:
Error of ESLint (Click to expand)
(node:36347) UnhandledPromiseRejectionWarning: /workspaces/cactbot-workspace/cactbot/eslint/cactbot-output-strings.js:107
stack.triggerID = node.parent.parent.properties.find((prop) => prop.key && prop.key.name === 'id')?.value?.value;
^
SyntaxError: Unexpected token ‘.’
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at /workspaces/cactbot-workspace/cactbot/node_modules/eslint-plugin-rulesdir/index.js:30:103
at Array.reduce (<anonymous>)
at Object.get rules [as rules] (/workspaces/cactbot-workspace/cactbot/node_modules/eslint-plugin-rulesdir/index.js:30:10)
(node:36347) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:36347) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:36347) UnhandledPromiseRejectionWarning: /workspaces/cactbot-workspace/cactbot/eslint/cactbot-output-strings.js:107
stack.triggerID = node.parent.parent.properties.find((prop) => prop.key && prop.key.name === ‘id’)?.value?.value;
^
SyntaxError: Unexpected token ‘.’
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at /workspaces/cactbot-workspace/cactbot/node_modules/eslint-plugin-rulesdir/index.js:30:103
at Array.reduce (<anonymous>)
at Object.get rules [as rules] (/workspaces/cactbot-workspace/cactbot/node_modules/eslint-plugin-rulesdir/index.js:30:10)
(node:36347) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
So it turns out that ESLint (or nodejs, precisely) didn’t know the new syntax of ES2020.
Then I found that ESLint in VSCode was called by the VSCode built-in Node.js environment, whose version is 12.18.3 now.
My VSCode Environment
Version: 1.55.1 (user setup)
Commit: 08a217c4d27a02a5bcde898fd7981bda5b49391b
Date: 2021-04-07T15:06:02.360Z
Electron: 11.3.0
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.19041
Fortunately, there is an option in the ESLint extension of VSCode to specify the runtime library that VSCode called (i.e. the built-in Node.js or the external ones that user installed), but to enable this option, user still have to manually select the current runtime in the GUI.
Here is the description of this option (eslint.runtime):
The location of the node binary to run ESLint under.
- When specified as a user/machine setting, the Node version from
eslint.runtimeautomatically replaces the built-in version.- When specified as a workspace setting,
eslint.runtimeallows you to switch to use that version with theESLint: Select Node version command.
Solution
Solution 1
To change the syntax of the cactbot-output-strings.js, not to use the brand new syntax, so that VSCode would be happy with the elder syntax.
(There are only 2 place that use the new syntax, so I think it is not difficult to make the change)
Solution 2
Let user change the eslint.runtime option in their own machine, this bug would also be solved. So that we don’t need to change any code of cactbot.
(But personally, I don’t like this solution, for example, I have both Linux and Windows to develop cactbot, I would be tired to switch between different runtime paths if goes this way.)
FYI, cc @Trim21 @panicstevenson
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (18 by maintainers)
Commits related to this issue
- build: add engine-strict to require node version This will throw errors when trying to run `npm` commands like `npm install`, e.g.: ``` npm ERR! notsup Unsupported engine for @typescript-eslint/pars... — committed to quisquous/cactbot by quisquous 2 years ago
- build: add engine-strict to require node version (#4242) This will throw errors when trying to run `npm` commands like `npm install`, e.g.: ``` npm ERR! notsup Unsupported engine for @typescript... — committed to quisquous/cactbot by quisquous 2 years ago
Should we set the node version in package.json to be >=14? Otherwise I think we should downgrade these to work with node 12
Since v14 is already the LTS, I think it is worth to set as mentioned.
I updated my local Node version as required and it works 100% fine, thanks ! My bad for not checking that first.
@MaikoTan I’m using VSCode on Windows 10 and was trying to commit onto GitHub, so no Linux involved at all there.