Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "const path" SyntaxError: Use of const in strict mode. #178

Closed
napcat opened this issue May 9, 2016 · 9 comments
Closed

Error "const path" SyntaxError: Use of const in strict mode. #178

napcat opened this issue May 9, 2016 · 9 comments

Comments

@napcat
Copy link

@napcat napcat commented May 9, 2016

I update to version 3.0.0 and I'm getting this error:

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)
@SamVerschueren
Copy link

@SamVerschueren SamVerschueren commented May 9, 2016

Upgrade your node version.

@napcat
Copy link
Author

@napcat napcat commented May 9, 2016

I'm currently using node version 5.4.1.

Can I update to a 5.x version or do I need to update to 6.x?

@SamVerschueren
Copy link

@SamVerschueren SamVerschueren commented May 9, 2016

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
Copy link
Author

@napcat napcat commented May 9, 2016

I was on 4.4.2LTS and update to 5.4.1 a fews weeks ago.
In the cmd:

C:>node -v
v5.4.1

C:>npm -v
3.5.3

@shinnn
Copy link
Contributor

@shinnn shinnn commented May 9, 2016

@napcat Add this code snippet to the top of your gulpfile:

console.log('Node version: ' + process.version);

then please show us the result.

@jaycom
Copy link

@jaycom jaycom commented May 10, 2016

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.

@shinnn
Copy link
Contributor

@shinnn shinnn commented May 10, 2016

@napcat Any feedback?

@napcat
Copy link
Author

@napcat napcat commented May 10, 2016

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...

@benrondeau
Copy link

@benrondeau benrondeau commented Aug 9, 2017

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:

vscode-toolbox

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.