当前位置:网站首页>Who moved my package lock
Who moved my package lock
2022-06-12 11:42:00 【Jioho_】
The bloody lesson is only to present a better article
package-lock Introduce
nodejs Yes package-lock Introduction to :package-lock.json file
The most important sentence is :
The purpose of this file is to track the exact version of each software package installed , So that the product can be used in the same way 100% Copy ( Even if the maintainer of the software package updates the software package ).
The emergence of problems
Today, a new project was launched , Just put the scaffolding of a project Copy Go to another project . Then all sorts of problems suddenly appeared .
The most outrageous thing is the same code , Another domain name is running well , All kinds of questions about new projects ... No mistake , No warning for local operation ~
The most obvious one is <slot></slot> Turn into undefined.
This means that the following operations do not achieve the desired results :
<!-- Ignore a pile vue Writing ... --> <slot>content</slot> <!-- The normal output is as follows --> content <!-- After packing --> It's empty , even to the extent that undefined
However, most of the components encapsulated in the project use the default slots , Some even added v-if The judgment of the , The content will not be displayed if the page is light , Repeat the entire page GG~
All this originated from :vue - Slot document 2.6.0 And then to slot Changed something .
The scenario of problem recurrence
- package-lock.json Is an ignored file
- Use vue.js And in vue.config.js Use external import in JS The way of introducing vue( Not from node_modules) Package generation
- Local debugging OK,CI After packing GG
- slot Most are default slots , And there are default contents in the default slot , Some slots even use v-if
- pageage.json Medium vue Version is
"vue":"^2.6.10". Dynamically introduced vue The version is also2.6.10
After some debugging, I found , Run locally vue The version uses 2.6.14. and vue-template-compiler The version of 2.6.14. However, it was introduced after packaging before the launch vue.js The version is 2.6.10!
But I don't think the ultimate problem is vue Version of , But when it comes to packing
vue-template-compilerVersion of ( Because if it's just vue The problem of , Previous projects have had problems for a long time , So it can only be parsed when packaging vue The version of the template library is also vue The version does not correspond to !)

So the last thing is to comment out vue.config.js Medium externals To configure . hold vue Of cdn Get rid of , Or use the packaging method to import vue.js. Solved the problem for the time being
PS:externals What is the configuration ?webpack - externals To configure
package.json Document symbol interpretation
Back to the problem of local debugging , Mingming package.json Is written 2.6.10 edition , Why do you actually use 2.6.14 ?
Look for the :"vue":"^2.6.10". Ahead ^, Also in package-lock.json file In the introduction , The following is a summary
Such symbols have a total of 4 individual
- ^ Indicates that only the master version number is locked :
"vue":"^2.6.10"Represents that the major version number is 2. The following will get the latest version under the main version number , Until now , The latest version is indeed 2.4.16 - ~ It means that only the major version number and minor version number are locked : Or to
"vue":"~2.6.10"For example , The main version is 2, The second version is 6, You will eventually get 2.6.x The latest version . - No symbols indicate that the version is locked :
"vue":"2.6.10"It will be designated as 2.6.10 . There will be no change *Represents the latest version . If it says"vue":"*". Which day? vue3.0 Updated to the stable version of the official website , After installation, you will directly upgrade to 3.0

summary :
^Lock master version~Lock master + Next versionemptyLock the specified version number*The latest version
How to find it quickly node_modules In the package
To understand the package.json After the definition of each symbol , Let's talk about how I found the problem : Recommend a vscode plug-in unit Search node_modules
After installation ,CTRL+P. Input >node

Then we can quickly search what we want to find npm package 
open vue Of package.json. although _form Is written 2.6.10. But the bottom is actually installed version yes 14 Of .


package-lock Do you want to delete ?
Before this happened , I usually put yarn.lock perhaps package-lock.json Delete first , stay npm i. Even in the project .gitignore Add them to the ignore file .
package-lock.json It will help you always lock the version number of the current running .
although package.json There is 4 Symbols , It seems that if ^ Such symbols will show that the whole program has been in the state of automatic version upgrade . It is extremely unstable for enterprise projects , that package-lock File can help you lock the current running environment .
Assuming the current package.json Of vue The version still says "vue":"^2.6.10". And now vue The latest version is "vue":"^2.6.14". At this time, a new project , The installation is "vue":"^2.6.14" rely on . meanwhile package-lock.json Will record vue Current 2.6.14 edition .
Even after a month ,vue Updated to 2.7.0. As long as there is package-lock.json Version record of , What are you doing npm i. It's all installed 2.6.14. It's kind of like package.json Medium “ Empty symbol ” It means .
Only the fully locked version , To ensure that “ Products can be used in the same way 100% Copy ( Even if the maintainer of the software package updates the software package )”
therefore , You dare to delete it package-lock.json Do you ?
summary
package.json The symbols are 4 individual
^Lock master version~Lock master + Next versionemptyLock the specified version number*The latest version
package-lock.json Delete and ignore as appropriate
- If you are a vigorous , A team willing to upgrade / personal , Directly change the version number to
"*" - If the project needs to be delivered continuously / Having high requirements for stable operation , Don't delete it
- And if you use webpack - externals To configure Do not delete , Because he will let you and you at any time CDN The version does not match the number ~
This leads to a series of“ It looks OK on my computer ”Illusion
- If you are a vigorous , A team willing to upgrade / personal , Directly change the version number to
A small plug-in is recommended
- Search node_modules I usually want to see some npm The source code of the package is also much more convenient
It was another day of learning from mistakes
边栏推荐
- ARM指令集之Load/Store指令寻址方式(一)
- VirtualBox virtual machine shut down due to abnormal system. The virtual machine startup item is missing
- 6.6 分離卷積
- 套接字实现 TCP 通信流程
- ioremap
- Basic principle of Doppler effect
- DS18B20 digital thermometer (I) electrical characteristics, power supply and wiring mode
- 【蓝桥杯单片机 国赛 第十一届】
- Byte order - how to judge the big end and the small end
- Golang Foundation (7)
猜你喜欢

Record the pits encountered when using JPA
![[the 11th national competition of Blue Bridge Cup single chip microcomputer]](/img/da/3c8a9efd5b28f67816f239531a0339.png)
[the 11th national competition of Blue Bridge Cup single chip microcomputer]

十折交叉验证代码中的问题

Selenium uses proxy IP

UML系列文章(31)体系结构建模---部署图

Inter class and intra class relations in video classification -- regularization

Lambda and filter, index of list and numpy array, as well as various distance metrics, concatenated array and distinction between axis=0 and axis=1

UML series articles (30) architecture modeling -- product diagram

Reentrantlock source code analysis

套接字编程TCP篇
随机推荐
一个人必须不停地写作,才能不被茫茫人海淹没。
LLD monitored by ZABBIX
Go sends SMS based on Tencent cloud
Golang Foundation (6)
Redis summary
【QNX Hypervisor 2.2 用户手册】4 构建QNX Hypervisor系统
Differences among various cross compiling tools of arm
ARM处理器模式与寄存器
单元测试用例框架--unittest
ARM指令集之Load/Store指令寻址方式(二)
postman传入list
进程的创建和回收
Windows10安装mysql-8.0.28-winx64
ARM指令集之Load/Store访存指令(一)
Design of tablewithpage
Deep learning and CV tutorial (14) | image segmentation (FCN, segnet, u-net, pspnet, deeplab, refinenet)
35. 搜索插入位置
字节序 - 如何判断大端小端
6.6 Convolution de séparation
890. find and replace mode