1.修改package.json文件
{"name": "wine-store-frontend","version": "0.0.0","private": true,"type": "module","scripts": {"dev": "vite --open","build": "vite build","preview": "vite preview"},// 在package。json中新增engines这个配置,用于指定node的版本"engines": {"node": "16.18.0"},"engineStrict": true,"dependencies": {"axios": "^1.6.8","vue": "^3.3.11","vue-router": "^4.2.5"},"devDependencies": {"vite": "^5.0.10"}
}
2.在vite项目根路径中创建.npmrc文件
3.在.npmrc文件中增加一行配置
# .npmrc
engine-strict = true
至此,已完成nodejs的版本锁定,如过使用了其他版本的nodejs,控制台会抛出错误信息
运行npm install
命令,会看到如下错误信息: