Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

node.js - How to easily verify correct npm dependencies installed?

How can I know when to prompt user to run npm install if there are any unmet package.json dependencies?

I would like to do this, because if any require() fails, the user gets a poor error message:

module.js:340
    throw err;
          ^
Error: Cannot find module 'nopt'

I've previously tried to just check for the existence of a node_modules directory, but this only works effectively for fresh git clones. I've also tried just requiring npm and running npm install as part of load, but that is very heavy weight.

I'm hoping there is a lighter weight library out there that just parses package.json and makes sure node_modules contents satisfy the requirements.

One idea was to use process.on('uncaughtException') to catch only module import errors, but looking to see if there is a "standard" solution first.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use yarn and do yarn check --verify-tree (you can continue using npm for everything else)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...