While browsing the metamask-extension source code, I saw a field in package.json: “packageManager”: “yarn@4.9.1”, but when checking yarn on npm, the latest version is still 1.22.22. Strange, so how does the actual project install this v4 yarn? After careful investigation, I found that it uses corepack for package manager and version management.
Aug 12, 2025
EventEmitter Initial Version class EventEmitter{ constructor(){ this.events={} } on(type,listener){ if(!this.events[type]){ this.events[type]=[] } this.events[type].push(listener) } emit(type,...args){ this.events[type].forEach(listener=>{ listener.call(this,...args) }) } off(type,listener){ if(this.events[type]){ const index=this.events[type].indexOf(listener) if(index!==-1){ this.events[type].splice(index,1) } } } once(type,listener){ const onceListener=(...args)=>{ listener.call(this,...args) this.off(type,onceListener) } this.on(type,onceListener) } } Testing const eventEmitter=new EventEmitter() const listener=(args)=>{ console.log(args); } eventEmitter.once('test',listener) eventEmitter.off('test',listener) eventEmitter.emit('test',{a:1}) When executing the above code, you’ll find that the test event was triggered once, but it should not execute because it was turned off. The solution is as follows.
Mar 18, 2025
When developing with npm, you may notice that if you delete the node_modules folder and then reinstall dependencies, the installation is very fast. This is because npm has a caching mechanism.
Feb 13, 2025
Besides dependency and devDependency in package.json, there’s also peerDependency. Let’s resolve a real-world error to understand how it works. Error Message npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: a@0.0.1-beta npm ERR! Found: ssh2@1.15.0 npm ERR! node_modules/ssh2 npm ERR! ssh2@"1.15.0" from the root project npm ERR! ssh2@"^1.12.0" from ssh2-sftp-client@9.1.0 npm ERR! node_modules/ssh2-sftp-client npm ERR! ssh2-sftp-client@"^9.1.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer ssh2@"1.16.0" from a@0.0.1-beta npm ERR! packages/a npm ERR! a@0.0.1-beta npm ERR! node_modules/a npm ERR! workspace packages/a from the root project npm ERR! npm ERR! Conflicting peer dependency: ssh2@1.16.0 npm ERR! node_modules/ssh2 npm ERR! peer ssh2@"1.16.0" from a@0.0.1-beta npm ERR! packages/a npm ERR! a@0.0.1-beta npm ERR! node_modules/a npm ERR! workspace packages/a from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! npm ERR! For a full report see: npm ERR! /Users/alanhe/.npm/_logs/2025-01-02T02_53_13_141Z-eresolve-report.txt npm ERR! A complete log of this run can be found in: npm ERR! /Users/alanhe/.npm/_logs/2025-01-02T02_53_13_141Z-debug-0.log Error Analysis The project’s direct dependency pins ssh2 at version 1.15.0, while package a lists ssh2@1.16.0 in its peerDependency field.
Jan 2, 2025
This article introduces security component scanning and handling in Node projects, including its advantages, implementation details, and relevant resources. These steps can help improve efficiency when handling security component scanning in Node projects.
Jun 2, 2024
Investigating why streaming writes cleared file contents when using SFTP in Node.js — the 'w' flag truncation and how it flows through.
Apr 27, 2024
This article introduces loading ES modules in Node.js projects, including its advantages, implementation details, and relevant resources. These steps can help improve efficiency when loading ES modules in Node.js projects.
Apr 10, 2024
This article introduces the inspect command in Node, including its advantages, implementation details, and relevant resources. These steps can help improve efficiency when using the inspect command in Node.
Dec 20, 2023
本文介绍关于前端开发常用npm包,包括使用场景、实现细节等,以提高关于前端开发常用npm包的效率。
Dec 20, 2023
本文是作者对Cannot use import statement outside a module的介绍,包括Cannot use import statement outside a module的优势、实现细节、相关资料等,这些步骤可以帮助作者提高Cannot use import statement outside a module的效率。
Oct 29, 2022