I'm able to use the latest versions of Chrome, Firefox, and Edge (Chromium) with Tampermonkey and they all support using const
in my userscript. However, for Opera 73.0.3856.284 with Tampermonkey 4.11.6120, I'm getting an error, "eslint: null - Parsing error: The keyword 'const' is reserved". While I know I can use var
or let
I was wondering if there was a specific reason that was causing this error. My userscript is inteded to be cross-browser and I was hoping if there was a way to use const without getting this error. The image below is just a userscript I made with only const to show the error:
Edit: I ran a test userscript with this code:
const x = 2;
alert(x);
and the alert gave 2. Thus, I suspect that the code is running fine, but this is an internal error by Tampermonkey. In fact, I strongly believe this to be the case as I just saw this issue: https://github.com/Tampermonkey/tampermonkey/issues/1099
What you're seeing is only a linting error for the in-browser editor provided by Tampermonkey, not a JavaScript runtime error. Your script should work just fine in modern versions of Opera; you can safely ignore the warning.
If you don't like the look of the warning, you can use an external script editor instead, eg, use:
// @require file://C:/PATH_TO_FILE.user.js
in the metadata block, with no content after the metadata block. Write the code in PATH_TO_FILE.user.js
instead.
If it hasn't already been reported, you could also raise an issue on Tampermonkey's github asking for a fix for the in-browser editor.