Not able to run nodemon (SyntaxError: Unexpected token) on ubuntu - node.js

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

Related

How to solve unexpected token issue in yarn installation

I install yarn on my server without any error, when I run yarn -v I get this error
I think the yarn did not install properly, what is wrong?
/usr/share/yarn/lib/cli.js:46100
let {
^
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 Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/share/yarn/bin/yarn.js:24:13)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
The error is caused by the old version of nodejs (usually lower than v6).
First install the latest stable version of nodejs or more recent version than you are using now.
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
https://github.com/nodesource/distributions/blob/master/README.md
Then install yarn:
https://yarnpkg.com/en/docs/install#debian-stable
Got same issue. The problem was that my PC has crashed while yarn install. Resolved with:
yarn cache clean

npm Error “ Cannot find module 'npmlog' ”

I am running CentOS 6 and after logging in, I encounter the following error
module.js:340
throw err;
^
Error: Cannot find module 'npmlog'
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 /home/dspace/.nvm/v0.10.31/bin/npm:19:11
at Object.<anonymous> (/home/dspace/.nvm/v0.10.31/bin/npm:87:3)
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)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `npm config delete prefix` or `nvm use --delete-prefix v0.10.31 --silent` to unset it.
I've discovered that it is a version bug and can be resolved either by upgrading the npm version or by deleting the node modules like so;
rm -rf node_modules
Then reinstalling them;
npm install
After removing the modules, npm install failed to run because of missing dependancies i.e. the modules. Now the command shows no response at all.
My node version is v0.10.48
This worked for me
Install nvm:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
Restart the terminal
Run
nvm install node
 
I had the same problem after proposed npm upgrade via npm -i -g npm. But Fedora npm/node installed via dnf has modules links to /usr/lib/node_modules/npm/node_modules.bundled/ from /usr/lib/node_modules/npm/node_modules/. I saw links were broken because usr/lib/node_modules/npm/node_modules.bundled/ disappeared. So reinstallation node,nodejs,npm via dnf/rpm solved the problem.

Truffle Fails on Start After Install

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

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

React-native init error

I'm trying to install React-native to my ubuntu 14.04. I have sucessfully installed react-native-cli, but when I'm trying to run react-native init reactApp trene is an error:
pavlov#pavlov-System-Product-Name:~$ node -v
v0.12.7
pavlov#pavlov-System-Product-Name:~$ react-native init reactApp
prompt: Directory reactApp already exist. Continue?: (no) y
This will walk you through creating a new React Native project in /home/pavlov/reactApp
Installing react-native package from npm...
You are currently running Node v0.12.7 but React Native requires >=4. Please use a supported version of Node.
See https://facebook.github.io/react-native/docs/getting-started.html
/home/pavlov/reactApp/node_modules/react-native/local-cli/cli.js:56
const setupEnvScript = /^win/.test(process.platform)
^^^^^
SyntaxError: Use of const in strict mode.
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Module._extensions..js (module.js:478:10)
at Object.require.extensions.(anonymous function) [as .js] (/home/pavlov/reactApp/node_modules/babel-core/lib/api/register/node.js:214:7)
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/pavlov/reactApp/node_modules/react-native/cli.js:15:18)
at Module._compile (module.js:460:26)
How can i fix it?
You definitely need to install Node 4.0 or higher. Actually it even says it in your console output.
Here is how i installed Node on my Ubuntu:
sudo apt-get install curl
curl --silent --location https://deb.nodesource.com/setup_4.x | sudo bash -
sudo apt-get install nodejs
Good luck!
Go to https://nodejs.org/en/ and download the latest version, in this case v4.4.3.

Resources