sveltekitesbuild

sveltekit or esbuild error: Two output files share the same path but have different contents


Just now, for no reason I can figure out, when I run npm run dev on my sveltekit project, I get this error:

✘ [ERROR] Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js.map

✘ [ERROR] Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js

> Build failed with 2 errors:
error: Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js.map
error: Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js
error: Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js.map
error: Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js
    at failureErrorWithLog (/repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1605:15)
    at /repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1251:28
    at runOnEndCallbacks (/repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1036:63)
    at buildResponseToResult (/repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1249:7)
    at /repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1358:14
    at /repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:668:9
    at handleIncomingPacket (/repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:765:9)
    at Socket.readFromStdout (/repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:635:7)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)

I have done this hundreds of times and it worked.

In case it matters, my repo is a rushjs monorepo, and I continually do update my dependencies using it, so maybe some version has bumped some place in my dependency tree, but I don't know how to debug it.

What causes this error?


Solution

  • Ok, the issue is that one of the modules in my app imported lodash cloneDeep like this

    import cloneDeep from lodash/cloneDeep

    i.e from the full lodash npm module.

    Another of my modules imported it using the more targeted npm module using

    import cloneDeep from "lodash.clonedeep"

    A very confusing error message, but I suppose it makes some sense.

    The fix was to import cloneDeep consistently, I chose the latter approach.