Aman Pandey
Aman Pandey

Reputation: 366

Issue loading dynamic chunk in React application using webpack

I am facing one issue where my react app is not able to load the lazily loaded chunk(Error: loading chunk 0 failed). Upon checking, I found the chunk is being requested from the relative url that is localhost.com:8000/chunk.js, instead of requesting it from the actual path that is set in the webpack config. My webpack config looks like below:

{
    ...
    output: {
      filename: '[name].client.bundle.js',
      chunkFilename: 'chunk.js',
      path: path.resolve(__dirname, '..', '.build', 'js'),
    },
 ...
}

The other file that is bundle.js loads correctly from localhost.com:8000/build/js/bundle.js. It's just the problem with this chunk that it's not loading from the builds directory. I would really appreciate any help on this. Thanks a ton in advance :)

Upvotes: 1

Views: 1444

Answers (1)

Aman Pandey
Aman Pandey

Reputation: 366

I just needed to set publicUrl in the output config and point it to /js. It works now! :)

Upvotes: 0

Related Questions