Truffle Fails on Start After Install - node.js

I installed Truffle just fine, but I can't call it without getting the following error:
/usr/local/lib/node_modules/truffle/build/cli.bundled.js:98908
function VM (opts = {}) {
^
SyntaxError: Unexpected token =
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 Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
System Spec:
uname -a
Linux 7ed9621f5250 4.1.12-103.7.1.el7uek.x86_64
NodeJS v4.2.6
npm v3.5.2
Install commands used:
apt-get update
apt-get -y install curl nodejs npm
ln -s /usr/bin/nodejs /usr/bin/node
npm install -g truffle
I can't find any docs or posts on this in order to troubleshoot. Please help. Thanks.

I was also stuck in this. I followed this which work for me, hope it also works for you.
Remove node and npm completely. Install fresh node and npm using :
wget https://nodejs.org/dist/v8.8.0/node-v8.8.0-linux-x64.tar.gz
sudo tar -xf node-v8.8.0-linux-x64.tar.gz --directory /usr/local --strip-components 1
node --version
npm --version
sudo npm install -g truffle
mkdir truffle-proj
cd truffle-proj
truffle init

Related

Not able to run nodemon (SyntaxError: Unexpected token) on ubuntu

command I am running : nodemon server.js,
error I am getting :
nodemon server.js
/usr/local/lib/node_modules/nodemon/node_modules/update-notifier/index.js:58
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/nodemon/bin/nodemon.js:15:3)
I tried various ways of installing nodemon on Ubuntu but still getting exact same error every time I run.
One reason could be your node.js installation is outdated.
You should upgrade to the recent version of node.js
You can check the version with:
node -v
If the version is recent, then you should try installing nodemon globally with this command
npm install -g nodemon # or using yarn: yarn global add nodemon
If you are stuck in an old version of node.js then do this:
sudo apt-get remove nodejs
sudo apt-get remove npm
Then go to /etc/apt/sources.list.d and remove any node list if you have. Then do a
sudo apt-get update
Check for any .npm or .node folder in your home folder and delete those.
If you type
which node
you can see the location of the node. Try which nodejs and which npm too.
Then do a fresh installation like this
cd ~
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
nano nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs

Add nodejs and npm to Jenkins docker image

I'm trying to do a quick experiment or two with Jenkins. For this I intended to use the jenkins image and add nodejs and npm to it. Here's what I'm trying to do:
FROM jenkins
USER root
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \
&& apt-get update \
&& apt-get install -y \
nodejs
RUN npm install -g npm
RUN npm --version
USER jenkins
The npm --version call will fail though, with this error:
Step 5/6 : RUN npm --version
---> Running in 48a250a4fdb8
module.js:471
throw err;
^
Error: Cannot find module 'process-nextick-args'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:26:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
The command '/bin/sh -c npm --version' returned a non-zero code: 1
What is the proper way (if any) to fix this?
Try the following, it uses docker multi-stage build to copy dependencies from one image to another. This will allow you to avoid all the special things that need to be done to install node in docker. There is an official docker image that is built by the docker team, so you use that as follows:
FROM node
FROM jenkins
USER root
COPY --from=0 /usr/local /usr/local
RUN npm --version
USER jenkins
npm --version will output 5.3.0
Jenkins image by docker uses minimal installation for running Jenkins
FROM node:15.4 as nodejs
ENV JENKINS_HOME /var/jenkins_home
USER root
RUN rm -rf /var/lib/apt/lists/*
RUN rm -rf /etc/apt/sources.list.d/*
RUN apt-get update
#INSTALL NODE
COPY --from=nodejs /usr/local /usr/local
RUN node -v
RUN npm -v

NPM breaks after it has been upgraded in docker container

I need to create a docker container with node v6.10.3, but with the latest npm (currently v5.4.1) to use new npm features for local packages.
Such installation runs without any problem on my Mac, but when I try to create a docker image with such an installation, after updating npm, the npm tool gets broken and throws a bunch of errors about missing packages.
Here is the example of the Dockerfile, with which I can reproduce this issue (note that my real Dockerfile is more complex):
FROM ubuntu:xenial
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN npm i -g npm
RUN npm i -g lerna
When the build process gets to the line RUN npm i -g lerna it throws a bunch of errors like:
Error: Cannot find module 'process-nextick-args'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:26:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Any other npm script would result in the same errors. Reinstalling all the packages on which npm depends, does not seem as a solution for me.
I have also tried to install node inside the container using nvm, but I got the same errors.
My docker version:
Docker version 17.06.2-ce, build cec0b72
What's wrong with this Dockerfile and what am I missing?
I have found a workaround for this issue, using yarn.
It looks weird, but it works:
FROM ubuntu:xenial
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN npm i -g yarn
RUN npm uninstall npm -g
RUN yarn global add npm
RUN npm i -g lerna
Still, it would be great if somebody can explain why the original solution did not work, and/or help find a better way to fix it.

Nuclide + Atom remote development des not work on Ubuntu 16.04

I trying to start Nuclide + Atom with remote development.
I've installed Nuclide via Package manager on Atom and install Nuclide Server (Ubuntu 16.04)
npm install -g nuclide
My first trouble was:
nohup: failed to run command 'node': No such file or directory
in nuclide-server-start log file, but i solve it by nodejs vs node on ubuntu 12.04
(don't think this right... :) but it works for me)
And i got a second trouble:
/usr/local/lib/node_modules/nuclide/pkg/nuclide-server/lib/nuclide-main.js:20
const {__DEV__} = require('../../nuclide-node-transpiler/lib/env');
^
SyntaxError: Unexpected token {
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 Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
in nuclide-server-start log file.
when i installing nuclide-server by npm it tells me
WARN engine nuclide#0.208.0: wanted: {"atom":">=1.14.1","node":">=6.5.0"} (current: {"node":"4.2.6","npm":"3.5.2"})
may is that a reason of my troubles?
Somebody help! :)
First i tried to update my nodeJS from npm:
$ sudo npm install -g node
and i got an answer:
npm WARN deprecated node#0.0.0: To update or install node, go to http://nodejs.org/
/usr/local/lib
└── node#0.0.0
then i try some way to update my nodeJs, described here: https://github.com/kevincobain2000/instagram-bot-api/issues/1
$ sudo npm cache clean -f && sudo npm install -g n && sudo n stable
npm WARN using --force I sure hope you know what you are doing.
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
/usr/local/lib
└── n#2.1.4
install : node-v7.6.0
mkdir : /usr/local/n/versions/node/7.6.0
fetch : https://nodejs.org/dist/v7.6.0/node-v7.6.0-linux-x64.tar.gz
######################################################################## 100.0%
installed : v7.6.0
and after that nuclide-server-start was successfully started! :)

Node forever doesn't work on Ubuntu 12.04.1

When I fun forever on Ubuntu 12.04.1, I got the error below after upgrading node.js from v0.6.12 to v0.8.15. Before upgrading it works well. Does anyone encounter this kind of issue before?
$ forever
module.js:340
throw err;
^
Error: Cannot find module './daemon.v0.8.15'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/usr/local/lib/node_modules/forever/node_modules/daemon/lib/daemon.js:12:11)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
My environment is
node v0.8.15
npm 1.1.66
I installed node and npm with the command line blow
$ sudo apt-get install python-software-properties -y
$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs npm -y
I installed forever with the command line
$ sudo npm install forever -g
'sudo npm update -g forever' doesn't work for me. I deleted all the installed modules and install it again. The forever works. The steps are as below.
Delete the all the existing forever modules.
$ sudo rm -R /usr/lib/node_modules/forever
$ sudo rm -R /usr/local/lib/node_modules/forever
Install the forever again.
$ sudo npm install forever -g
You will get he solution with below commands but some issue, so please try the PM2 with so many advantages and check points of debuting
$ sudo rm -R /usr/lib/node_modules/forever
$ sudo rm -R /usr/local/lib/node_modules/forever
Please use this for debuting the node.js exception and monitoring the process of each and every with clustering and master and slave logic
http://devo.ps/blog/2013/06/26/goodbye-node-forever-hello-pm2.html
$ sudo npm install -g pm2

Resources