mathiasbynens / jsesc

Given some data, jsesc returns the shortest possible stringified & ASCII-safe representation of that data.
https://mths.be/jsesc
MIT License
716 stars 48 forks source link

Node 4.5.0 fails to run jsesc #32

Closed stevendesu closed 8 years ago

stevendesu commented 8 years ago

I have a project which depends on gulp-angular-templatecache which in turn depends on jsesc. Using Node 4.4.7 it works fine, but after upgrading to Node 4.5.0 it fails with three errors:

By removing strict mode, replacing every instance of let with var, and converting key to a var 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.

mathiasbynens commented 8 years ago

How can I reproduce the issue? Do you have a minimal test case?

stevendesu commented 8 years ago

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

stevendesu commented 8 years ago

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:

  1. sudo apt-get install nodejs nodejs-legacy npm
  2. mkdir test
  3. cd test
  4. npm init (follow prompts)
  5. npm install --save jsesc
  6. echo "require('jsesc')" >> index.js
  7. 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.

stevendesu commented 8 years ago

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

mathiasbynens commented 8 years ago

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.