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

Error: Conflict: Multiple chunks emit assets to the same filename ssr-bundle.js #29

Closed
edwardfxiao opened this issue Feb 12, 2019 · 7 comments · May be fixed by #31 or #51
Closed

Error: Conflict: Multiple chunks emit assets to the same filename ssr-bundle.js #29

edwardfxiao opened this issue Feb 12, 2019 · 7 comments · May be fixed by #31 or #51
Labels
duplicate This issue or pull request already exists question Further information is requested

Comments

@edwardfxiao
Copy link

edwardfxiao commented Feb 12, 2019

Hi, I have encountered this problem when I was trying to create multiple html files with multiple entries.

Error: Child compilation failed:
  Error: Conflict: Multiple chunks emit assets to the same filename ssr-bundle.js (chunks 1 and 2  )
//webpack config
config.entry = {
  a: './a.js',
  b: './b.js',
}

Object.keys(config.entry).map(i => {
  config.plugins.push(
    new HtmlWebpackPlugin({
      template: `!!prerender-loader?string!./template.html`,
      filename: `${i}.html`,
      hash: false,
      chunks: [i],
    }),
  );
});

I have tried below but doesnt make any difference.

template: `!!prerender-loader?${JSON.stringify({ string: true, params: { url: `/${i}/` } })}!./template.html`
        "html-webpack-plugin": "^4.0.0-alpha.2",
        "prerender-loader": "^1.2.0",
        "webpack": "^4.29.3",
        "webpack-assets-manifest": "^2.0.0",
        "webpack-cli": "^3.1.1",
        "webpack-dev-server": "^3.1.14"

node v11.9.0.

Any ideas?

@edwardfxiao
Copy link
Author

edwardfxiao commented Feb 13, 2019

Testing repo https://github.com/edwardfhsiao/prerender-loader-test-repo

$ npm i
$ npm run compile

template: `!!prerender-loader?string!${PATH.HTML_PATH}/template.html` locates in production.config.js file

@developit
Copy link
Collaborator

developit commented Feb 22, 2019

I'm wondering if removing the cache inheritance would fix this:
https://github.com/GoogleChromeLabs/prerender-loader/blob/master/src/index.js#L131-L143
nope

developit added a commit that referenced this issue Feb 22, 2019
@developit
Copy link
Collaborator

I think I found the issue, I was using os.tmpdir(), but had meant to use fs.mkdtempSync().

@developit
Copy link
Collaborator

@edwardfhsiao alright, I figured out the issue with the demo you linked above: it's a duplicate of #25, and the solution I posted there a couple hours ago works here too:

Object.keys(config.entry).map(i => {
  config.plugins.push(
    new HtmlWebpackPlugin({
-     template: `!!prerender-loader?string!${PATH.HTML_PATH}/template.html`,
+     template: `!!prerender-loader?string&entry=${config.entry[i]}!${PATH.HTML_PATH}/template.html`,
      // etc
    }),
  );
});

@developit developit added duplicate This issue or pull request already exists question Further information is requested labels Feb 22, 2019
@edwardfxiao
Copy link
Author

edwardfxiao commented Feb 22, 2019

@developit Awesome, that solved my problem. Really appreciate your help!

@northamerican
Copy link

@edwardfhsiao @developit

This issue may have to be looked at again. The error still occurs if using the {{prerender}} in the template tag as specified in the docs:
https://github.com/GoogleChromeLabs/prerender-loader#injecting-content-into-the-html

I spent many hours trying to debug our config and was still getting the multiple chunks error until i realized this.

To replicate, replace the template.html file in the example repo (https://github.com/edwardfhsiao/prerender-loader-test-repo) with:

<div id="root">{{prerender}}</div>

and run npm run compile or yarn compile.

It's not clear where the <%= htmlWebpackPlugin.options.title %> formatting comes from, but using {{prerender}} in the template as specified in the docs fails with multiple entry files.

I can open a new issue if needed.

@edwardfxiao
Copy link
Author

edwardfxiao commented May 5, 2019

@northamerican <%= htmlWebpackPlugin.options.title %>just comes from

 new HtmlWebpackPlugin({
      ...
      title: `${i}`,

It is a format of HtmlWebpackPlugin, which does not really matter in this case.

As for the multiple entry issues, I guess still needs @developit 's help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Further information is requested
Projects
None yet
3 participants