The REPL makes const variables not const if await appears in the input:
const x = 1; x = 2; await 0; x
Known issue. See https://github.com/nodejs/node/pull/15566:
While this works well for
var, it doesn't for top-levelletandconst(letandconststill work as expected in blocks), which will lose their lexical specialness (or constantness) with this approach. However, I simply can't think of any good way to support top-levelletandconstfully. (Note, DevTools has the same problem; tryconst a = await Promise.resolve(1);back-to-back multiple times.) If you've got an idea, please comment!
The RFC at the end is still active!
working on fix in https://github.com/bmeck/node/tree/env-record-repl-await , also fixes some other bugs
I'm unable to replicate this. Any chance this never went out in a release without a subsequent fix? Should this be closed? Or am I just testing wrong somehow?
Ah, never mind, I see I need to use the --experimental-repl-await flag. Seeing the bug now.
@Trott is the --experimental-repl-await flag supposed to work now?
Because I can't have the --experimental-repl-await working properly.
$ node --experimental-modules --experimental-repl-await src/login.js
(node:484) ExperimentalWarning: The ESM module loader is experimental.
file:///opt/src/login.js:8
const browser = await puppeteer.launch({
^^^^^
SyntaxError: Unexpected reserved word
at Loader.moduleStrategy (internal/modules/esm/translators.js:84:18)
at async link (internal/modules/esm/module_job.js:36:21)
--experimental-repl-await only enables top-level await within the repl (that's why it has repl in the name).
Oh so there's no way to have top level-await in a script now, correct?
Most helpful comment
Known issue. See https://github.com/nodejs/node/pull/15566:
The RFC at the end is still active!