Closed stevendesu closed 8 years ago
How can I reproduce the issue? Do you have a minimal test case?
Today at work I will work on getting a minimal test case together. I noticed the issue in a project which was compiling for my coworkers but not for me, and the only difference we could find was the version of NodeJS installed
Pinning down the repro steps is proving confusing - mostly because figuring out exactly which version of Node I'm using is proving confusing. Originally I found this issue while trying to build a very large project using Visual Studio. According to the Task Runner Explorer, I was using Node v4.5.0
I then created a project which repro'd the issue perfectly on Bash on Ubuntu on Windows (Windows Subsystem for Linux), so I thought I had it pinned down. However my sample project did not repro when running it via Command Prompt. According to Bash on Ubuntu on Windows, my node version is v0.10.25, and according to Command Prompt my node version is v4.5.0
So the issue can certainly be reproduced, but it's hard to pin down if it's tied to a particular version of Node. I also don't know why it failed in Visual Studio but works via Command Prompt.
If you have a Windows PC and you're willing to set up the Windows Subsystem for Linux, here's the simplest test case:
sudo apt-get install nodejs nodejs-legacy npm
mkdir test
cd test
npm init
(follow prompts)npm install --save jsesc
echo "require('jsesc')" >> index.js
node index.js
This produces the following output for me:
/mnt/c/Users/sbarnett/test/node_modules/jsesc/jsesc.js:3
const object = {};
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/mnt/c/Users/sbarnett/test/index.js;1:75)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
I'll let you know if I figure out anything else about this bug.
Just confirmed that on Ubuntu 14.04 (Trusty) I get the same behavior with the 7 repro steps. Ubuntu 14.04 installs Node v0.10.25 by default (without specifying custom PPAs)
It seems to be an issue with older versions of NodeJS. Will try to figure out why Visual Studio is failing despite claiming to use v4.5.0
Yeah, it really looks like an older, unsupported version of Node.js is being used (despite you having installed v4+ elsewhere). I’m gonna close this issue since Node.js < v4 isn’t supported in jsesc v2 anymore.
I have a project which depends on
gulp-angular-templatecache
which in turn depends onjsesc
. Using Node 4.4.7 it works fine, but after upgrading to Node 4.5.0 it fails with three errors:SyntaxError: Use of const in strict mode.
line 3,const object = {};
SyntaxError: Unexpected token in
line 6,for (const key in object) {
SyntaxError: Unexpected identifier
line 25,let index = -1;
By removing strict mode, replacing every instance of
let
withvar
, and convertingkey
to avar
in the for-loop it worked for me. Of course I assume you don't want to remove strict mode, so another solution is probably better suited.