npm install
different with ^
:
1 | $ npm install express@^4.16.1 --save --save-exact |
ref: https://docs.npmjs.com/cli/install
npm list
check the installed packages under current folder:
1 | $ npm list |
upgrade node to given version
linux
install
n
widget as tool upgrading node:1
2
3
4root@f7748a275a7a:/# node -v
v14.5.0
root@f7748a275a7a:/# npm cache clean -f
npm WARN using --force I sure hope you know what you are doing.1
2
3
4root@f7748a275a7a:/# npm install -g n
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
+ n@6.7.0
added 1 package from 4 contributors in 0.205sinstall node with given version:
1
2
3
4
5root@f7748a275a7a:/# n v14.6.0
installing : node-v14.6.0
mkdir : /usr/local/n/versions/node/14.6.0
fetch : https://nodejs.org/dist/v14.6.0/node-v14.6.0-linux-x64.tar.xz
installed : v14.6.0 (with npm 6.14.6)1
2root@f7748a275a7a:/# node -v
v14.6.0windows
use
nvm
to manage node version on windowsinstall
nvm
:
downloadnvm-setup.zip
from https://github.com/coreybutler/nvm-windows/releases then installcheck and switch node version:
check installed node version:1
$ nvm ls
install node with given version:
1
$ nvm install vXX
choose certain installed verision:
1
$ nvm use xxx
if error occurs like:
1
2
3
4$ nvm install v10.15
10.15.0
Could not retrieve https://nodejs.org/dist/latest/SHASUMS256.txt.
Get https://nodejs.org/dist/latest/SHASUMS256.txt: dial tcp 104.20.22.46:443: i/o timeoutfind nvm location with
where nvm
and modify thesettings.txt
under the path, add:1
2node_mirror:npm.taobao.org/mirrors/node/
npm_mirror:npm.taobao.org/mirrors/npm/node js run unit test (mocha)
ref: https://blog.csdn.net/weixin_42429288/article/details/97638626
run single test
Addonly
before target case or suite, like1
2
3
4
5
6
7
8
9it.only('XXX-1035 ....', async () => {
await db.initDB();
await Area.dumpTestData2('../../test/UT/data/Area1.json');
await agent.get('/test/v1/xxx?origin=xxxx1')
.expect(200,[ { out: 2,
in: 1,
region: 'region1',
adminZones: [ 'Zona Norte', 'Madrid Captial' ] } ])
});can also add it before a suite, like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17describe.only('#digestAPI test()', async () => {
before(async () => {
await db.initDB();
const express = require('express');
app = express();
serverDigest.baseRoute(app,9999);
agent = request.agent(app);
});
after(async function () {
// process.exit();
});
it('XXX-980 ...', async () => {
...
}
}skip single Test
same way asonly
, you can add it afterdescribe
orit
to skip certain suite/case.
npm ERR! Maximum call stack size exceeded
Error came out when run npm install --save --save-exact react-scripts@4.0.1
Solution:
- upgrade npm to a newer version, it worked for me after I switching to npm v6.14.6 from npm v6.4.1
- delete
package-lock.json
and runnpm rebuild
, if not work, delete the npm_modules folder.
Node Sass does not yet support your current environment
1 | $ npm run build |
Solution:
- uninstall node-sass:
npm uninstall --save node-sass
- reinstall node-sass:
npm install --save node-sass
Update:
new issue occur: Error: Node Sass version 5.0.0 is incompatible with ^4.0.0.
Solution:
- uninstall node-Sass
- install node-sass version before v5.0.0:
npm install --save node-sass@4.14.1
upgrade globally installed npm packages
check out-dated packages:
1 | $ npm outdated -g |
update all global packages:
1 | npm update -g |
update specific global package:
1 | npm update -g <package_name> |
react-scripts dependency error
error message:
1 | react-scripts package provided by Create React App requires a dependency: |
I tried to update babel-eslint globally but seems it was not out-dated, not sure why react use this new version.
solution:
- Add
.env
file under project with the following statement:1
SKIP_PREFLIGHT_CHECK=true
- Save
.env
and deletepackage-lock.json
npm install
->npm start
cannot install chart.js from react-chartjs-2
compling failed like:
1 | ERROR in ./~/react-chartjs-2/lib/index.js |
The reason is that, chart.js is a peer dependancy. we should include a version in package.json.
But after running npm install --save chart.js
, the react-chartjs-2 module got error:
1 | TypeError: Cannot read property 'defaults' of undefined |
resolved with
1 | # firstly uninstall chart.js v3 |