You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import 'dayjs/locale/zh-cn';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.locale('zh-cn');
dayjs.Ls['zh-cn'].weekStart = 1;
dayjs.extend(relativeTime);
The products generated are in two forms:
and
The difference in build products leads to a domino-like effect that makes most file hashes change.
After looking at the source code, I found that the main thing is that vite builds with the worker execution @rollup/plugin-commonjs plugin turned on, and the code is written in such a way that dayjs and import 'dayjs/locale/zh-cn'; seem to have no dependency on each other, resulting in them being executed in the main process and the worker process respectively The order of execution is uncertain, sometimes dayjs is built first, sometimes zh-cn.js is executed first, which leads to different final packaged products.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
The code is as follows:
The products generated are in two forms:
and
The difference in build products leads to a domino-like effect that makes most file hashes change.
After looking at the source code, I found that the main thing is that vite builds with the worker execution @rollup/plugin-commonjs plugin turned on, and the code is written in such a way that dayjs and import 'dayjs/locale/zh-cn'; seem to have no dependency on each other, resulting in them being executed in the main process and the worker process respectively The order of execution is uncertain, sometimes dayjs is built first, sometimes zh-cn.js is executed first, which leads to different final packaged products.
Reproduction
not have
Steps to reproduce
Same as the bug description above
System Info
Used Package Manager
npm
Logs
// packages/commonjs/src/resolve-require-sources.js
const setInitialParentType = (id, initialCommonJSType) => {
// Fully analyzed modules may never change type
if (fullyAnalyzedModules[id]) {
return;
}
knownCjsModuleTypes[id] = initialCommonJSType;
if (id.indexOf('dayjs.min.js') !== -1) {
console.log('requiredIds: ', requiredIds); // Logs manually added to the source code
}
if (
detectCyclesAndConditional &&
knownCjsModuleTypes[id] === true &&
requiredIds[id] &&
!unconditionallyRequiredIds[id]
) {
knownCjsModuleTypes[id] = IS_WRAPPED_COMMONJS;
}
};
The contents of the log are of the following two kinds:
requiredIds: [Object: null prototype] {}
and
requiredIds: [Object: null prototype] {
'/Users/userName/projectName/node_modules/dayjs/dayjs.min.js': true
}
Validations
The text was updated successfully, but these errors were encountered: