Can't use NPM Commands - Block-scoped declaration - node.js

I've been using npm for a while now but now every time I try to run any npm command I get the following error.
I have no idea how to fix this.
USER-mbp:/ USER$ npm -v
/Users/USER/.nvm/versions/node/v5.12.0/lib/node_modules/npm/bin/npm-cli.js:85
let notifier = require('update-notifier')({pkg})
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:148:18)
at node.js:405:3
Any help would be appreciated!
If there is any information missing, I'll update as soon as I can!

You might need to update your node version.
here is a question explaining how:
How do I update Node.js?
They will recommend you to install Node Version Manager (NVM)
once you have that installed you want to run:
nvm install node //"node" is an alias for the latest version
Good luck!

Related

nodemon unexpected identifier [duplicate]

Whenever I try to run nodemon to auto-restart my local server (running on port 3000), I get this error message regarding a syntax error in the no
/Users/SI23/.nvm/versions/node/v6.5.0/lib/node_modules/nodemon/node_modules/chokidar/index.js:151
async remove(item) {
^^^^^^
SyntaxError: Unexpected identifier
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:528:28)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/SI23/.nvm/versions/node/v6.5.0/lib/node_modules/nodemon/lib/monitor/watch.js:6:16)
at Module._compile (module.js:556:32)
Any way to fix this?
As per my knowledge
Async Await is not available in node v6.5.0,
which you are using. So you can upgrade your node version or can start using Promise object with the same version of node.
In my case, npm list chokidar helped me realize it was another module (gulp-nodemon) that used a newer version of chokidar. It worked after downgrading it.
I had exactly the same error...! it was a node version problem, I was on node version 6, this is what I did to fix it:
nvm install <VERSION_NUMBER> // nvm install 10.15.3
nvm use <VERSION_NUMBER> // nvm use 10.15.3
node -v // confirm i am using the correct version of node
Remember to do this on your computer not just your code file and change the default node version with nvm alias default 10.15.3
you can check your default lists with
nvm list

NodeJS stopped working after changing version

I was working on Node version 9.1.0 but the client asked me to use NVM so that the version can be switched at will. I tried but it was not working. So I uninstalled NodeJS from my windows machine and did a fresh install of NodeJS version 8.9.4
After npm install when I tried to execute the code I got this error:
SyntaxError: Unexpected number
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\inetpub\wwwroot\NodeJS_APIs\api\node_modules\lodash\isFunction.js:1:80)
The line that trew the error is in vm.js:
function createScript(code, options) {
return new Script(code, options);//This is the line
}
I don't understand what went wrong. Can someone please explain what am I doing wrong?
From your error stacktrace it seems the error is related to your loadash library, Can you please try uninstalling it using,
npm uninstall lodash
And then reinstall a compatible lodash version like this,
npm install lodash#4.17.5
Once done, try running your script again.
Hope this helps!
You might get some hints from here, although I’m not sure: https://github.com/rollup/rollup/issues/2054

Ember Installation Issue: SyntaxError: Use of const in strict mode

When trying to install Ember.js on Windows (and possibly other systems), after running the following commands:
npm install -g npm
npm install -g ember-cli
npm install -g bower
No errors are raised, how the command ember -v outputs the following:
C:\Users\<user>\AppData\Roaming\npm\node_modules\ember-cli\lib\cli\index.js:3
const willInterruptProcess = require('../utilities/will-interrupt-process');
^^^^^
SyntaxError: Use of const in strict mode.
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at C:\Users\Shayn\AppData\Roaming\npm\node_modules\ember-cli\bin\ember:26:11
at C:\Users\Shayn\AppData\Roaming\npm\node_modules\ember-cli\node_modules\resolve\lib\async.js:50:13
at processDirs (C:\Users\Shayn\AppData\Roaming\npm\node_modules\ember-cli\node_modules\resolve\lib\async.js:182:39)
This suggests an issue with my Ember installation, how can I address this?
The solution is suggested in a few other answers, for example this one, however this exact solution will not work on Windows.
Instead, the best solution is to get the latest version of Node installed via an installer.
To verify after installation try the following:
node --version
Which should output something like:
v8.9.1
Previously this command would have given a lower version number. In my case it was similar to v0.12.

Compiled with `coffee` stopped working

I'm not sure what I've done, but I can no longer compile CoffeeScript files. I keep getting the following, regardless of which file I'm trying to compile. I've tried reinstalling coffee by running sudo npm remove --global coffeescript and then sudo npm install --global coffeescript. Automatic compilation in Atom using the coffee-compile package still works. How can I resolve this?
user#computer:~/some/path $ coffee -c code.coffee
/usr/local/lib/node_modules/coffeescript/lib/coffeescript/command.js:23
({spawn, exec} = require('child_process'));
^
ReferenceError: Invalid left-hand side in assignment
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/coffeescript/bin/coffee:15:5)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
You have CoffeeScript 2+ installed, which requires Node 6 or later; but your Node runtime is < 6. (The error specifically is that the Node runtime chokes on the ({spawn, exec} = destructuring syntax, which Node < 6 doesn’t understand.) Either install CoffeeScript 1.x or Node 6+.
Got the same on Ubuntu 16.04.3 LTS, fixed simply by
$ sudo npm remove --global coffeescript
$ sudo apt-get install coffeescript

Trouble installing audiosprite on Ubuntu Server 16.04

I keep getting this error message, and I'm unable to trouble-shoot this or see where anyone else is having the same problem.
I followed the instructions to install this on Linux, but audiosprite is producing this error message. Is this an issue with audiosprite? Or nodejs? Or something else?
Using v4.2.6 of node if that matters:
# audiosprite --help
/usr/local/lib/node_modules/audiosprite/audiosprite.js:31
let opts = {}, callback = function(){}
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/audiosprite/cli.js:7:19)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
Upgrade your nodejs and npm version. The keyword let,const are not supported by v4.0. You have to update version
The module n makes version-management easy:
sudo npm install n -g
sudo n 0.12.2
For the latest stable version:
sudo n stable
For the latest version:
sudo n latest

Resources