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

Comments

5 participants
@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

This comment has been minimized.

Show comment
Hide comment
@SamVerschueren

SamVerschueren May 9, 2016

Collaborator

Upgrade your node version.

Collaborator

SamVerschueren commented May 9, 2016

Upgrade your node version.

@napcat

This comment has been minimized.

Show comment
Hide comment
@napcat

napcat 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?

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

This comment has been minimized.

Show comment
Hide comment
@SamVerschueren

SamVerschueren May 9, 2016

Collaborator

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

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@napcat

napcat 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

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

This comment has been minimized.

Show comment
Hide comment
@shinnn

shinnn May 9, 2016

Collaborator

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

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

then please show us the result.

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@jaycom

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

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

This comment has been minimized.

Show comment
Hide comment
@shinnn

shinnn May 10, 2016

Collaborator

@napcat Any feedback?

Collaborator

shinnn commented May 10, 2016

@napcat Any feedback?

@napcat

This comment has been minimized.

Show comment
Hide comment
@napcat

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

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

This comment has been minimized.

Show comment
Hide comment
@benrondeau

benrondeau 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

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