D:\project\node_modules\gulp-imagemin\index.js:2
const path = require('path');
^^^^^
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> (D:\project\gulpfile.js:87:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
Are you sure you are on node 5.x (node -v)? As long as you are on node >=4, you should be good to go.
http://stackoverflow.com/questions/22603078/syntaxerror-use-of-const-in-strict-mode
@napcat Add this code snippet to the top of your gulpfile:
console.log('Node version: ' + process.version);
then please show us the result.
I updated the lib, and get this issues too,
Then I reinstall the nodejs version 4.4.4 and npm 3.8.9
it's work.
Yes, I think I found the solution..
If I run the command in the cmd there's no error and the version logs correctly.
Here is the full log:
D:\project>gulp build
**Node version: v5.4.1**
[10:19:43] Using gulpfile D:\project\gulpfile.js
[10:19:43] Starting 'build'...
[10:19:43] Starting 'clean'...
[10:19:43] Finished 'clean' after 22 ms
[10:19:43] Starting 'html'...
[10:19:43] Finished 'html' after 1.45 ms
[10:19:43] Starting 'assets'...
[10:19:43] Finished 'assets' after 3.7 ms
[10:19:43] Starting 'js'...
[10:19:43] Finished 'js' after
[10:19:43] Finished 'build' after
[10:19:51] gulp-imagemin: Minified 2 images (saved 3.59 kB - 2.3%)
But I'm using Visual Studio 2015. In Visual Studio 2015 there's a UI to run the gulp tasks, the "Task Runner Explorer". The exact same gulpfile breaks the task runner in VS with the following output:
Failed to run "D:\project\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
D:\project\node_modules\gulp-imagemin\index.js:2
const path = require('path');
^^^^^
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> (D:\project\gulpfile.js:86:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
I searched a bit and with your help, I found out that VS installs an old node version and probably VS was using it. I had to go to Tools > Options > Projects and Solutions > External Web Tools and add the current nodejs path "C:\Program Files\nodejs".
It's working now. Thank you for the help, and sorry for the trouble...
If someone is running the 'Task Runner' tool in Visual Studio (I am using 2017 but should be true in previous versions), it ships with an old version of node which doesn't support ES6. Turning off this version of node to run gulp tasks solves this issue:
This menu can be found here: Tools > Options > Projects and Solutions > Web Package Management > External Web Tools and DESELECT the option for $(VSINSTALLDIR)\Web\External