How to solve unexpected token issue in yarn installation - node.js

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

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

Ubuntu 16.04 - nodejs cannot find module despite being installed globally

Fresh Ubuntu 16.04 installation. Installed nodejs 10.15 according to the official instructions
# curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
# apt-get install nodejs
Then installed ws globally
# npm install -g ws
+ ws#6.1.3
updated 1 package in 0.374s
Then in a js file I do:
const WebSocket = require('ws');
Then run it:
# nodejs ws.js
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module 'ws'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/var/nfs/nodes/api/arbitrage/hotbit.js:1:81)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
It appears the global modules are installed in /usr/lib/node_modules but apps still fail unless I manually say
export NODE_PATH=/usr/lib/node_modules
Is this a bug?

gitbook-cli install error, gitbook-cli -v cannot be use

after i install the nodejs and npm , gitbook-cli ,there is an error.like this:
[root#vagrant-centos65 vagrant]# gitbook -v
/usr/lib/node_modules/gitbook-cli/node_modules/fs-extra/lib/index.js:3
const assign = require('./util/assign')
^^^^^
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> (/usr/lib/node_modules/gitbook-cli/lib/config.js:2:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
[root#vagrant-centos65 vagrant]# npm -v
1.3.6
[root#vagrant-centos65 vagrant]# node -v
v0.10.48
my nodejs version and npm are v0.10.48 ,1.3.6 ,what should i do ,please help me .
As this answer explain, const support is not enabled by default in node.js version 0.10 and require --harmony flag if you want to use it.
As this version of fs-extra package use const keyword in his index.js file, you got this error.
You can have a look at this compatibility table for a summary for const and let support by version.
Just upgrade your node.js version to solve this issue.
Also, I don't think it is a good idea to launch gitbook as root user.
thanks # TGrif , i upgrade my nodejs ,and its worked.
npm cache clean -f
npm install -g n
n stable
ln -sf /usr/local/n/versions/node/8.0.0/bin/node /usr/bin/node
How do I update Node.js?

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.

Error: cannot find module 'mime'

I am trying to install cartodb on ubuntu 12.04. I have done all the steps mentioned on https://github.com/danseely/cartodb-install/blob/master/DEV-INSTALLATION.md and I am stuck at the Install Windshaft-cartodb Step. The following steps worked fine:
cd ~
git clone git://github.com/CartoDB/Windshaft-cartodb.git
cd Windshaft-cartodb
git checkout master
npm install
cp config/environments/development.js.example config/environments/development.js
Whenever I hit the command node app.js development, it gives me following error:
module.js:340
throw err;
^
Error: Cannot find module 'mime'
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> (/home/user/Windshaft- cartodb/node_modules/windshaft/node_modules/grainstore/node_modules/millstone/lib/millstone.js:6:12)
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)
at require (module.js:380:17)
I installed mapnik using
sudo add-apt-repository ppa:mapnik/v2.2.0
sudo apt-get update
sudo apt-get install libmapnik libmapnik-dev mapnik-utils python-mapnik
#harinish This problem occur due to many reasons, one of the peculiar reason is, if you have different versions of the Node JS installed on your system. Check this Github discussion
But the best way to resolve this issue of missing module, install it using the NPM as follows:
npm install mime
Remember the command install into the current directory from where you are executing this command. If you want to install globally use it with -g switch as follows:
npm install mime -g
Then run the program, it will be resolved.

Resources