npm node enconding

2019-08-12 08:52发布

问题:

I want to npm install the following validate .json

{
    "name": "node-todo",
    "version": "0.0.0",
    "description": "Simple todo application",
    "main": "server.js",
    "dependencies": {
        "express": "~3.4.4",
        "mongoose": "~3.6.2"
    }, 
    "private": true
}

but the npm install doesn't seem to work because I even cant npm install a sample json from http://package-json-validator.com/

I installed npm and nodejs with the following commands

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh

Now I want to use npm install but the shell gives me this npm ERR! install Couldn't read dependencies npm ERR! Failed to parse json npm ERR! Unexpected token / npm ERR! Failed to parse package.json data. npm ERR! package.json must be actual JSON, not just JavaScript. npm ERR! npm ERR! This is not a bug in npm. npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! System Darwin 13.0.0
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.3.14
npm ERR! code EJSONPARSE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR! not ok code 0

I'm using Sublime and saved the json as a UTF-8 (without the BOM tag)

回答1:

Assuming you are running ubuntu or that you are using the aptitude package manager

apt-get install -y python-software-properties python g++ make
add-apt-repository ppa:chris-lea/node.js
apt-get install nodejs
apt-get install npm

Then run this when needed to update the sources.list and install the latest version.

apt-get update
apt-get upgrade nodejs

If you want to downgrade node simply use

apt-get install nodejs={version number}


回答2:

Linux Installation - node.js:

  • Via package manager for many distros:
    https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

    Or

  • Via download binaries (this worked for me after many problems with other solutions)

    a) download from https://nodejs.org/download/release/latest/
    b) move to /usr/local/

    Note: To avoid permissions problems when install none modules globally (npm install -g ...) you must to move files preserving your ownership.

    i) Unpack as normal user, ie, not sudo:
    tar -zxvf node-package.tar.gz

    ii) Move properly (-p same as -preserve=mode,ownership,timestamps):
    sudo cp -rp node-package/* /usr/local/ && rm -rf node-package

Linux Installation - npm

  • Be sure you have node.js already installed (node -v):

    curl https://www.npmjs.org/install.sh | sh

    Note: www.npmjs.org/install.sh is the new URL after February 2014