tweb
tweb copied to clipboard
[BUG] pnpm build failed
✓ 781 modules transformed. rendering chunks (28)...The emitted file "lang-5a385cdb.js" overwrites a previously emitted file of the same name. The emitted file "langSign-66e8939d.js" overwrites a previously emitted file of the same name. The emitted file "pluralPolyfill-61f068d6.js" overwrites a previously emitted file of the same name. The emitted file "countries-5301fc59.js" overwrites a previously emitted file of the same name. The emitted file "lang-5a385cdb.js.map" overwrites a previously emitted file of the same name. The emitted file "langSign-66e8939d.js.map" overwrites a previously emitted file of the same name. The emitted file "pluralPolyfill-61f068d6.js.map" overwrites a previously emitted file of the same name. The emitted file "countries-5301fc59.js.map" overwrites a previously emitted file of the same name. [vite:build-import-analysis] Cannot read properties of undefined (reading 'forEach') ✓ built in 39.95s error during build: TypeError: Cannot read properties of undefined (reading 'forEach') at addDeps (file:///home/tweb/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-24daf00c.js:45215:55) at Object.generateBundle (file:///home/tweb/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-24daf00c.js:45236:33) at file:///home/tweb/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:24412:40 ELIFECYCLE Command failed with exit code 1.
Same issue

someone have solution for this error?
@morethanwords @ezrawic4j We have faced the same issue. Is there any solution?
I've found that some of the chunks have no imports field array as lang.ts and that's why the chunk.imports.forEach method in the mentioned vite file doesn't exist and throwing an error due to the field is undefined
And when I fixed the file by adding conditions - the build has been successful
So maybe the problem with the chunk generation or something else
So maybe the problem with the chunk generation or something else
It is. The bug is inside the vite. In order to build it, conditionals should be added in vite/dist/node/chunks/dep-24daf00c.js on lines 45215 and 45218 this way:
So maybe the problem with the chunk generation or something else
It is. The bug is inside the vite. In order to build it, conditionals should be added in vite/dist/node/chunks/dep-24daf00c.js on lines 45215 and 45218 this way
I see, thanks. As I understand it's your official workaround for this bug. Can you write an issue to the specific package (rollup/vite) to fix the problem from the root?
Compilation error reported:
PS \tweb> vite build
has built solid true
vite v4.3.1 building for production...
✓ 1111 modules transformed.
rendering chunks (30)...The emitted file "lang-49055ff2.js" overwrites a previously emitted file of the same name.
The emitted file "pluralPolyfill-61f068d6.js" overwrites a previously emitted file of the same name.
The emitted file "countries-5301fc59.js" overwrites a previously emitted file of the same name.
The emitted file "langSign-66e8939d.js" overwrites a previously emitted file of the same name.
The emitted file "lang-49055ff2.js.map" overwrites a previously emitted file of the same name.
The emitted file "pluralPolyfill-61f068d6.js.map" overwrites a previously emitted file of the same name.
The emitted file "langSign-66e8939d.js.map" overwrites a previously emitted file of the same name.
[vite:build-import-analysis] Cannot read properties of undefined (reading 'forEach')
✓ built in 48.32s
error during build:
TypeError: Cannot read properties of undefined (reading 'forEach')
at addDeps (/tweb/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-24daf00c.js:45215:55)
at Object.generateBundle (/tweb/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-24daf00c.js:45239:33)
at /tweb/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:24412:40
Solution: Find the error line in the dep-24daf00c.js file and modify it:
Aboriginal:
chunk.imports.forEach(addDeps);
// Ensure that the css imported by current chunk is loaded after the dependencies.
// So the style of current chunk won't be overwritten unexpectedly.
chunk.viteMetadata.importedCss.forEach((file) => {
deps.add(file);
});
Modified:
if (chunk.imports){
chunk.imports.forEach(addDeps);
}
// Ensure that the css imported by current chunk is loaded after the dependencies.
// So the style of current chunk won't be overwritten unexpectedly.
if (chunk.viteMetadata && chunk.viteMetadata.importedCss){
chunk.viteMetadata.importedCss.forEach((file) => {
deps.add(file);
});
}
Finally, run the 'vite build' again and compile it successfully.
https://github.com/morethanwords/tweb/issues/269#issuecomment-1825082899
Hello @morethanwords, I am having this issue when trying to migrate quite a huge frontend project from CRA to Vite and this is the only things stopping me currently
Do you know if they will approve and let your fix into production?
Do you know if they will approve and let your fix into production?
Not sure yet, you could also ask them here https://github.com/vitejs/vite/pull/15469, maybe they will change the priority from minor.
Thanks for answering, I have found a solution on my end
I used "build": "vite build --minify false", in order to not minimize the code
in node_modules I applied your fix and console logged the files that did not have imports
By looking into the files in the dist I was able to deduce where they belonged, in my case it came from dependencies in jszip
In my vite.config.ts I added manual chunking to make sure they were added into one chunk
build: {
outDir: "build",
target: "es2020",
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes("jszip") || id.includes("pako")) {
return "jszip";
}
if (id.includes("node_modules")) {
return "vendor";
}
return "index";
},
},
},
},```