Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error (the same filename for multiple chunks) when import an image twice with the same filename #18272

Closed
1 of 4 tasks
shlajin opened this issue Jul 24, 2023 · 6 comments · Fixed by #27159
Closed
1 of 4 tasks
Assignees
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug

Comments

@shlajin
Copy link

shlajin commented Jul 24, 2023

Current Behavior

When I try to serve my project, I get this error

[webpack-dev-middleware] Error: Conflict: Multiple chunks emit assets to the same filename preview.png (chunks main and main)

Expected Behavior

I should get no error; images should have different names.

GitHub Repo

https://github.com/shlajin/nx-multiple-chunks-bug-demo

Steps to Reproduce

I started with a brand new repo to illustrate the problem.

npx create-nx-workspace --pm yarn
Need to install the following packages:
  [email protected]
Ok to proceed? (y) y

 >  NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Where would you like to create your workspace? · multiple-chunks-bug-demo
✔ Which stack do you want to use? · react
✔ What framework would you like to use? · none
✔ Standalone project or integrated monorepo? · integrated
✔ Application name · multiple-chunks-bug-demo
✔ Which bundler would you like to use? · webpack
✔ Default stylesheet format · css
✔ Enable distributed caching to make your CI faster · No

 >  NX   Creating your v16.5.5 workspace.

I added a library (no tests, not buildable, not publishable).

yarn nx g @nx/react:lib sample-library

I added 2 different images into the following folders:

libs/sample-library/src/lib/apple/preview.png
libs/sample-library/src/lib/orange/preview.png

And added 2 files next to each of the images that simply import and re-export the image:

// libs/sample-library/src/lib/orange/Orange.ts
import Preview from './preview.png';

export const orangeData = {
  image: Preview,
};


// libs/sample-library/src/lib/apple/Apple.ts
import Preview from './preview.png';

export const appleData = {
  image: Preview,
};

Then, in libs/sample-library/src/index.ts I re-exported my 2 files:

import { appleData } from "./lib/apple/Apple"
import { orangeData } from "./lib/orange/Orange"

export const data = {
  appleData,
  orangeData
}

To recap, I have 2 folders named apple and orange, each folder contains a preview.png file and one .ts file each. The *.ts file simply re-exports the image (obtains the image URL as per default behaviour), and the index.ts of the whole library re-exports the *.ts files.

Now if I try to use the images in the app, e.g.

// apps/multiple-chunks-bug-demo/src/app/app.tsx
import { data } from "@multiple-chunks-bug-demo/sample-library"

export function App() {
  return (
    <div>
      <h1>DEMO</h1>
      <img src={data.appleData.image} />
      <img src={data.orangeData.image} />
    </div>
  );
}

export default App;

and run

yarn nx serve multiple-chunks-bug-demo

I get

[webpack-dev-middleware] Error: Conflict: Multiple chunks emit assets to the same filename preview.png (chunks main and main)

I attached a demo repo for your convenience.

Thank you!

Nx Report

Node   : 18.14.0
   OS     : darwin-arm64
   yarn   : 1.22.19

   nx                 : 16.5.5
   @nx/js             : 16.5.5
   @nx/jest           : 16.5.5
   @nx/linter         : 16.5.5
   @nx/workspace      : 16.5.5
   @nx/cypress        : 16.5.5
   @nx/devkit         : 16.5.5
   @nx/eslint-plugin  : 16.5.5
   @nx/react          : 16.5.5
   @nrwl/tao          : 16.5.5
   @nx/web            : 16.5.5
   @nx/webpack        : 16.5.5
   typescript         : 5.1.6

✨  Done in 0.83s.

Failure Logs

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@AgentEnder AgentEnder added the scope: bundlers Issues related to webpack, rollup label Jul 25, 2023
@Schmale97
Copy link
Contributor

I am also seeing this after upgrading from 16.3 to 16.6

@CurtisHughes
Copy link
Contributor

Seems like the hash got removed from the outputted file name. I think it might be related to #17763

@triglian
Copy link

Seems like it only happens with the dev server. The production builds continue to have the hash. cc @jbadeau

Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Mar 12, 2024
@shlajin
Copy link
Author

shlajin commented Mar 19, 2024

bump

@github-actions github-actions bot removed the stale label Mar 20, 2024
ndcunningham pushed a commit that referenced this issue Jul 29, 2024
…#27159)

Our assets are generated as flat assets in dist, which allows using
assets from workspace libs. This prevents users from having different
assets with the same filename (e.g. `foo/image.png` and
`bar/image.png`). This will error out in the dev server with conflicting
filenames.

We cannot use `[path][name]` because of assets that are outside of the
app folder (e.g. `../../libs/ui/src/assets/image.png`). Thus the best
option is to include hash.

Note: Also re-enabled the e2e tests for `react.test.ts` file since it is
now using Playwright instead of Cypress.

## Current Behavior
Assets with the same filename will error in dev-mode.

## Expected Behavior
Assets with the same filename works.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #18272
FrozenPandaz pushed a commit that referenced this issue Jul 30, 2024
…#27159)

Our assets are generated as flat assets in dist, which allows using
assets from workspace libs. This prevents users from having different
assets with the same filename (e.g. `foo/image.png` and
`bar/image.png`). This will error out in the dev server with conflicting
filenames.

We cannot use `[path][name]` because of assets that are outside of the
app folder (e.g. `../../libs/ui/src/assets/image.png`). Thus the best
option is to include hash.

Note: Also re-enabled the e2e tests for `react.test.ts` file since it is
now using Playwright instead of Cypress.

## Current Behavior
Assets with the same filename will error in dev-mode.

## Expected Behavior
Assets with the same filename works.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #18272

(cherry picked from commit 0710fea)
ZackDeRose pushed a commit to ZackDeRose/nx that referenced this issue Aug 8, 2024
…nrwl#27159)

Our assets are generated as flat assets in dist, which allows using
assets from workspace libs. This prevents users from having different
assets with the same filename (e.g. `foo/image.png` and
`bar/image.png`). This will error out in the dev server with conflicting
filenames.

We cannot use `[path][name]` because of assets that are outside of the
app folder (e.g. `../../libs/ui/src/assets/image.png`). Thus the best
option is to include hash.

Note: Also re-enabled the e2e tests for `react.test.ts` file since it is
now using Playwright instead of Cypress.

## Current Behavior
Assets with the same filename will error in dev-mode.

## Expected Behavior
Assets with the same filename works.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes nrwl#18272
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants