Why do you use normal regular expressions on the browser side, but report an error in node.js?

I want to write a simple way to compress js files, but I have a problem using regularities.

let newStr = str.replace(/(?<!(var|let|const|function))\s/g, "");

the rule is normal in browsers, but an error is reported in node.js

let newStr = str.replace(/(?<!(var|let|const|function))\s/g, "");
                ^

SyntaxError: Invalid regular expression: /(?<!(var|let|const|function))\s/: Invalid group
    at Object.<anonymous> (c:\Users\Administrator\Desktop\test2\test2.js:6:17)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3

should be a compatibility issue.
previous js only supported advance assertions, but now chrome also supports later assertions.
if you don't use npm, you can upgrade node to 10. I've tried this version is supported
if you want to use npm, try 8.12 and 9. I didn't try this.
8.9 doesn't work anyway.
by the way, you don't have to add a semicolon when you wrap a line at the end of a js sentence, but you can't do it in this regular situation.
Compression js should be left to uglify.js


regular syntax is not supported, because in js, (? .

Menu