Parcel: Parcel 2: Bundles must have unique filePaths when using duplicate content in files

Created on 20 Aug 2019  ยท  12Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

When including two files with the same content and name but in different folders, the build fails with Bundles must have unique filePaths.

๐ŸŽ› Configuration (.babelrc, package.json, cli command)

None, see example here: https://github.com/garthenweb/parcel2-unique-filePaths-example

๐Ÿค” Expected Behavior

In a perfect world parcel should detect that both assets are equal and could just include one in the bundle. But I can imagine that this might have side effects.
I would be fine if the build would not fail. A warning would be nice as well as I was not aware that I have duplicate files in my bundle before running parcel 2.

๐Ÿ˜ฏ Current Behavior

Errors with

๐Ÿšจ Bundles must have unique filePaths
    at BundlerRunner.nameBundles (<path>/node_modules/@parcel/core/lib/BundlerRunner.js:121:21)
    at async BundlerRunner.bundle (<path>/node_modules/@parcel/core/lib/BundlerRunner.js:92:5)
    at async Parcel.build (<path>/node_modules/@parcel/core/lib/Parcel.js:289:25)
    at async Parcel.run (<path>/node_modules/@parcel/core/lib/Parcel.js:196:18)
    at async Command.run (<path>/node_modules/parcel/lib/cli.js:132:7)

๐Ÿ’ Possible Solution

Including the file path into the hash generation would maybe help.

๐Ÿ”ฆ Context

I was running parcel 2 on a bigger code base and had round about 10 files of type scss, svg and js in the bundle that caused this error. I detected the files by adding the following into the BundleRunner.js file which throw the error:

console.log(bundlePaths.filter((val, index,list) => {
  return list.indexOf(val) !== index;
}))

While creating the example project I found out that css files worked perfectly fine but for scss files it was failing.

๐Ÿ’ป Code Sample

See example here: https://github.com/garthenweb/parcel2-unique-filePaths-example

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 2.0.0-alpha.1.1
| Node | v12.8.1
| npm | 6.10.2
| Operating System | Max OSX

Bug โœจ Parcel 2

Most helpful comment

leaving this for anyone running into this issue: if you have a "main" field in package.json that says "index.html" and also run parcel build index.html you get this error.

just remove the "main" field and ur good.

All 12 comments

In a perfect world parcel should detect that both assets are equal and could just include one in the bundle. But I can imagine that this might have side effects.

Exactly, that's unfortunately not possible: https://github.com/parcel-bundler/parcel/issues/3368

This doesn't seem to happen anymore on the current v2 branch...

@mischnic I can proof that it is better now as the scss files do not throw any longer but I still have issues with SVGs. I might want to add this to the example, can maybe do it at the weekend if required.
The following is the current output of a real project (when adding the log as described in the description).

[
  '<path>/build/arrow-white-down.928b77cd.svg',
  '<path>/build/ic-alert-error.d572df0c.svg',
  '<path>/build/server.js'
]

@mischnic I just updated the example including svg files. Unfortunately, I cannot check with the latest v2 branch as I get a syntax error:

๐Ÿšจ Unexpected identifier
import type {Readable} from 'stream';
       ^^^^

SyntaxError: Unexpected identifier
  at Module._compile (internal/modules/cjs/loader.js:811:22)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:879:10)
  at Module.load (internal/modules/cjs/loader.js:731:32)
  at NodePackageManager.load (<path>/parcel/packages/core/package-manager/lib/NodePackageManager.js:104:9)
  at NodePackageManager.requireSync (<path>/parcel/packages/core/package-manager/lib/NodePackageManager.js:70:17)
  at Module.m.require (<path>/parcel/packages/core/package-manager/lib/NodePackageManager.js:91:19)
  at require (internal/modules/cjs/helpers.js:68:18)
  at Object.<anonymous> (<path>/parcel/packages/transformers/babel/lib/flow.js:8:14)
  at Module._compile (internal/modules/cjs/loader.js:868:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:879:10)


๐Ÿšจ Error writing to cache: function (...args) {
  return new Promise(function (resolve, reject) {
  fn(...args, function (err, ...re...<omitted>... } could not be cloned.

Looks like something is wrong with the build, but should not be related to this issue. Maybe you have more luck?

When trying to bundle two files without the same name/content(and i also tried in different folders) i get the same issue, but only while using the watch mode and there's no cache already there.

parcel watch src/index.ts src/index2.ts

index.ts
ts console.log('foo')

index2.ts
ts console.log('bar')

ร— Bundles must have unique filePaths at BundlerRunner.nameBundles (C:\dev\epk\node_modules\@parcel\core\lib\BundlerRunner.js:121:21) at async BundlerRunner.bundle (C:\dev\epk\node_modules\@parcel\core\lib\BundlerRunner.js:92:5) at async Parcel.build (C:\dev\epk\node_modules\@parcel\core\lib\Parcel.js:289:25)

If there's already a cache from a previous parcel build, e.g using the non watch version, parcel src/index.ts src/index2.ts, the build ran in watch mode work properly

For my case this is fixed now. I still had issues with the server.js but it looks like it was due to a bad configuration.

leaving this for anyone running into this issue: if you have a "main" field in package.json that says "index.html" and also run parcel build index.html you get this error.

just remove the "main" field and ur good.

@sw-yx I think your case is slightly different than the original bug here, but useful for people searching. I'm working on making this error message better. I think what likely happened was you accidentally had two targets defined in your package.json pointing to the same output path. This wouldn't happen with the CLI argument as that's an entry, not a target.

Better error message in the works for that case:

image

I'm definitely seeing this error with [email protected] and can't seem to fix it after following suggestions on this issue. When can we expect a new alpha version with better error messages?

Maybe related #3875 ?

@swashcap I checked the PR here and in the description it is mentioned that having multiple entry points in package.json could lead to this issue. That was exactly the issue I had with the same version as you. It might help to check out that PR.

@swashcap Same here, on a project with no duplicate source files.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shiloa picture shiloa  ยท  39Comments

Znarkus picture Znarkus  ยท  38Comments

devcati picture devcati  ยท  45Comments

v0idifier picture v0idifier  ยท  51Comments

jssee picture jssee  ยท  46Comments