commonjs
Summary: require a file is to execute the file synchronously. After the file is executed, the file export value will be cached. When accessing it again next time, you only need to take out the cache, and there is no need to execute the file twice.
esm
esm exports the memory address, when other files are imported, it will point to the same address
export value can be modified
How to avoid being modified
- If it's just one layer of objects, then use
- If there are nested objects, each object needs to be recursively Object.freeze