question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Path of dynamic chunks is relative

See original GitHub issue

The chunks resulting from a dynamic import are incorrectly loaded into the page. Their path is relative to the page thus causing 404 errors. To solve this I try to set the publicPath in Webpack config as suggested in https://github.com/webpack/webpack/issues/7968

    output: {
        path: path.resolve(__dirname, 'dist'),
        publicPath: "/",
        filename: "[name].[contenthash].js",
    },

Unfortunately that raises a Django SuspiciousFileOperation:

The joined path (/main.9ce82b7ec94c17ac77f9.css) is located outside of the base path component

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kierandarcycommented, Mar 4, 2021

Thank you for the update @bluesurfer your solution fixed my issue too. Also, thank you @knokit - I made a small update and I now no longer need my custom loader.

I just needed to update my WebpackManifestPlugin like this

new WebpackManifestPlugin({ publicPath: "" })
1reaction
bluesurfercommented, Mar 4, 2021

My previous comment was too overkill 😃

In my case, I finally solved this issue with the following settings:

Webpack configuration

    ....
    output: {
          path: path.resolve(__dirname, "dist"),
          publicPath: "/static/",
          filename: "[name].[contenthash].js",
      },
    ....
    plugins: [
        new WebpackManifestPlugin({
            publicPath: ""
        }),
    ],

Django settings

STATIC_URL = "/static/"
STATICFILES_DIRS = [str(ROOT_DIR / "dist")]

So to me this issue is closed… I’ll let the maintainer @shonin to consider closing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Correctly resolve dynamic chunk paths relative to the current ...
Feature request Correctly load a bundled dynamic javascript import file relative to the current script file. What is the expected behavior?
Read more >
React-loadable gets chunks only from relative path
Question: How do I tell react or webpack to use the absolute path /js/ for fetching chunks? Here is my webpack.config.json var path...
Read more >
Code Splitting - webpack
Entry Points: Manually split code using entry configuration. Prevent Duplication: Use Entry dependencies or SplitChunksPlugin to dedupe and split chunks.
Read more >
Mastering code splitting with webpack | Diel Duarte blog
code splitting is a build time process that splits pieces of your code into async chunks, let's talk about how Webpack can help...
Read more >
How code-splitting and dynamic Import works - WPACK.IO
src/main.js', output: { // Create a dir dist in the project root path: ... 'dist'), // filename filename: 'bundle.js', // The URL relative...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found