Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm error Syntax error: word unexpected (expecting ")")

Tags:

node.js

npm

I am trying to install the npm package "serialport" to work with Node.js on Ubuntu.

I have Node.js version 4.3.1

And when I try to install using

sudo npm install serialport

I get the following error;

/usr/local/bin/node: 1: /usr/local/bin/node: Syntax error: word unexpected (expecting ")")

Actually I'm not even able to install npm. I have dependencies missing; I'm on Ubuntu 15. How do I install npm?

When I try to install NPM I get the following error:

Les paquets suivants contiennent des dépendances non satisfaites :
 npm : Dépend: nodejs mais ne sera pas installé
       Dépend: node-abbrev (>= 1.0.4) mais ne sera pas installé
       Dépend: node-ansi (>= 0.3.0-2) mais ne sera pas installé
       Dépend: node-ansi-color-table mais ne sera pas installé
       Dépend: node-archy mais ne sera pas installé
       Dépend: node-block-stream mais ne sera pas installé
       Dépend: node-fstream (>= 0.1.22) mais ne sera pas installé
       Dépend: node-fstream-ignore mais ne sera pas installé
       Dépend: node-github-url-from-git mais ne sera pas installé
       Dépend: node-glob (>= 3.1.21) mais ne sera pas installé
       Dépend: node-graceful-fs (>= 2.0.0) mais ne sera pas installé
       Dépend: node-inherits mais ne sera pas installé
       Dépend: node-ini (>= 1.1.0) mais ne sera pas installé
       Dépend: node-lockfile mais ne sera pas installé
       Dépend: node-lru-cache (>= 2.3.0) mais ne sera pas installé
       Dépend: node-minimatch (>= 0.2.11) mais ne sera pas installé
       Dépend: node-mkdirp (>= 0.3.3) mais ne sera pas installé
       Dépend: node-gyp (>= 0.10.9) mais ne sera pas installé
       Dépend: node-nopt (>= 3.0.1) mais ne sera pas installé
       Dépend: node-npmlog mais ne sera pas installé
       Dépend: node-once mais ne sera pas installé
       Dépend: node-osenv mais ne sera pas installé
       Dépend: node-read mais ne sera pas installé
       Dépend: node-read-package-json (>= 1.1.0) mais ne sera pas installé
       Dépend: node-request (>= 2.25.0) mais ne sera pas installé
       Dépend: node-retry mais ne sera pas installé
       Dépend: node-rimraf (>= 2.2.2) mais ne sera pas installé
       Dépend: node-semver (>= 2.1.0) mais ne sera pas installé
       Dépend: node-sha mais ne sera pas installé
       Dépend: node-slide mais ne sera pas installé
       Dépend: node-tar (>= 0.1.18) mais ne sera pas installé
       Dépend: node-underscore mais ne sera pas installé
       Dépend: node-which mais ne sera pas installé
E: Impossible de corriger les problèmes, des paquets défectueux sont en mode « garder en l'état »

It's French but basically saying that some dependencies are missing. It doesn't detect that I have nodejs installed.

But when I try to reinstall Node it is telling me that I already have a better version.

I also noticed that I have node and npm in /usr/local/bin but I also have another folder /node-v4.3.1-linux-armv6l/ that contain a /bin with node and npm but also some more folders like /include, /lib ,/share

like image 679
MadeInDreams Avatar asked Dec 15 '22 08:12

MadeInDreams


2 Answers

To install npm:

sudo apt-get update
sudo apt-get install npm

And then I'm pretty sure you should remove that sudo when installing packages:

npm install serialport

Here's some more information: https://www.digitalocean.com/community/tutorials/how-to-use-npm-to-manage-node-js-packages-on-a-linux-server

like image 112
Tropic Avatar answered Jan 06 '23 05:01

Tropic


I know there is already a marked answer, but it didn't help me.

The error says that there is an error code in javascript file, so I tried to execute this javascript with node:

# nodejs /path_where_npm_is_linked/npm-cli.js

and that works! So I think npm command was not being executed with the right program. Maybe the problem is the other executable 'node' which it has no relation with nodejs, or in the link itself (npm is a link to npm-cli.js). Even the enviroment variable NODE_PATH is configured to nodejs.

So I tried to make my own npm command:

add

alias npm='nodejs /opt/node-v6.11.1-linux-ppc64/bin/npm'

to .bashrc (or other terminal configuration file if you are under other distro) or .bash_aliases (they are inside user home folder) Restart the terminal and voilà :D

Edit: some packages won't install even with this modification (like node-sass). So a symbolic link must be done ln -s path_to_nodejs(ex. /usr/bin/nodejs) /usr/bin/node

like image 23
Shil Nevado Avatar answered Jan 06 '23 03:01

Shil Nevado