SyntaxError: Use of const in strict mode inside github and codeship - node.js

I've found following error when I run grunt test inside my source code Github/Codeship.
In setup command inside codeship, following code are configured like that.
nvm install 0.12.6
nvm use 0.12.6
npm install grunt-cli bower -g
npm install
bower install -p
npm run update-webdriver
and test commands inside codeship;
grunt test
But that error not found inside my source code, and actually found inside github/codeship by viewing following error message given by codeship. Because those folder structure is not defined as we configure in our server. Please help me how to solve it. Thanks.
Using 2 x hasMany to represent N:M relations has been deprecated. Please use belongsToMany instead
>> Mocha exploded!
>> /home/rof/src/github.com/MyProjects/node_modules/sparkpost/node_modules/request/node_modules/hawk/node_modules/boom/lib/index.js:5
>> const Hoek = require('hoek');
>> ^^^^^
>> 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 Object.<anonymous> (/home/rof/src/github.com/MyProjects/node_modules/sparkpost/node_modules/request/node_modules/hawk/lib/index.js:5:33)
>> at Module._compile (module.js:460:26)
>> 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 Object.<anonymous> (/home/rof/src/github.com/MyProjects/node_modules/sparkpost/node_modules/request/request.js:9:12)
>> at Module._compile (module.js:460:26)
Warning: Task "mochaTest:src" failed. Use --force to continue.

Because those folder structure is not defined as we configure in our server.
This issue has nothing to do with folder structures.
Your project is currently using Node version 0.12.6 which is extremely out of date. The current LTS version of Node is 6.11.3 and the current version is 8.6.0.
The specific issue is SyntaxError: Use of const in strict mode. which means the libraries you are using are currently utilizing ES2015 syntax or higher. The root cause of the issue is in the Boom module, which uses const at line 5 (and most likely other current syntax as well).
The solution for your issue here is to update the node version being utilized inside Codeship.
nvm install 6.11.3
nvm use 6.11.3

simple way. just upgrade your node by below code:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
enjoy!

Related

Can't use NPM Commands - Block-scoped declaration

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!

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

ubuntu nodejs syntax error Syntax Error: Unexpected token `

I went through the process of installing the VolumioUI on Ubuntu
as explained in this link.
and I get:
/Volumio2-UI$ gulp serve --theme="volumio"
/home/yossi/elia/Volumio2-UI/gulp/build.js:127
fs.readFileSync(`${conf.paths.src}/app/themes/${themeSelected}/assets/va
^
SyntaxError: Unexpected token ILLEGAL
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 /home/yossi/elia/Volumio2-UI/gulpfile.js:19:3
at Array.map (native)
at Object.<anonymous> (/home/yossi/elia/Volumio2-UI/gulpfile.js:18:4)
at Module._compile (module.js:456:26)
I did the same process on MAC with no problems.
This is very strange since it complains about a syntax error.
if I change it to ' than it works fine, the problem is that the code is full of this error.
Can I config NodeJs to treat ` as '
?
Note: I was able to solve it by search-and-replace, but I leave this question open because I would like to know if it can be solved with a config
$ node --version
v0.10.25
Backticks are part of the new syntax introduced in the latest version of Javascript (ES6).
The problem occurs, because you have a (very) old version of node, which does not implement this new syntax. Probably, you have node v.0.10 instead of node v.7
The solution is to upgrade node.js.
Here is how (Ubuntu 14), see https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
This is the solucion with the problem for Invalid or unexpected token when you use npm install.
Backticks are different from single quotes, they aren't interchangeable by means of setting a configuration option somewhere.
You need a relatively recent Node.js version (v4.4.2 or up, I think) that supports the backtick ("template literal") syntax.

Getting meteor 0.9.2 build to work OSX -> Linux

I was using meteor 0.8.x but recently tried to upgrade to 0.9.2. It works locally but I'm not having any luck with meteor bundle or meteor build
First I got this error
/var/projects/myproject/live/bundle/programs/server/boot.js:198
}).run();
^
Error: /var/projects/myproject/live/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/build/Release/bcrypt_lib.node: invalid ELF header
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 bindings (/var/projects/myproject/live/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/node_modules/bindings/bindings.js:74:15)
at Object.<anonymous> (/var/projects/myproject/live/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/bcrypt.js:1:97)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Things I've tried
Made sure live/bundle/programs/server/node_modules does not exist before starting.
ran npm install in live/bundle/programs/server as the README says to
Things I noticed. There's no bcrypt deps in live/bundle/programs/server/package.json. In 0.8.2 I had commands to install both fibers and bcrypt manually but apparently I don't need the fibers one anymore. It looks like I do need the bcrypt one but it's in a different location than it used to be.
I don't see anything in the docs about needing to go to /var/projects/myproject/live/bundle/programs/server/npm/npm-bcrypt and install bcrypt. I can manually delete it but am I doing something wrong?
Like I said I'm already installing it where 0.8.2 needed it in programs/server. Should I be manually installing in program/server/npm/npm-bcrypt? Should I add that to my list of places to ignore
I put that in just to try it and so now I get this error
/var/projects/myproject/live/bundle/programs/server/node_modules/fibers/future.js:173
throw(ex);
^
Error: Cannot find module 'websocket-driver'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/projects/myproject/live/bundle/programs/server/npm/ddp/node_modules/faye-websocket/lib/faye/websocket.js:8:14)
at Module._compile (module.js:456:26)
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)
Is that yet another module I need to manually install? I'm getting the impression I'm just doing something fundamentally wrong.
I've got the following meteor packages
.meteor/packages
# Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
standard-app-packages
audit-argument-checks
iron:router#0.9.3
meteorhacks:npm#1.2.0
npm-container
packages.json
{
"semver": "2.3.1",
"winston": "0.7.3",
"winston-loggly": "1.0.1"
}
note: I'm developing/bundling on OSX but deploying on Ubuntu.
I had similar problems - I posted my solution over on DO
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-meteor-js-application-on-ubuntu-14-04-with-nginx?comment=19780
UPDATE - Here is the answer from that forum:
If anyone else has an issue like this with bcrypt - the app probably has its own copy in
/home/yourapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/
delete that noise. Then do this.
cd /home/yourapp/bundle/programs/server
npm install bcrypt
Then
cp -r /home/yourapp/bundle/programs/server/node_modules/bcrypt /home/yourapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/
then start your app and enjoy the meteory goodness.
On the general problem of . . .
(for those stumbling here via Google)
Cannot find module 'MODULE-NAME'
or
Can't find npm module 'MODULE-NAME'
If you've recently added or removed packages while the application is running, try stopping and restarting your meteor application.
// stop ( "CTRL+C" in terminal that launched process )
$ kill `ps ax | grep '[m]eteor' | awk '{print $1}'`
// start
$ meteor

Resources