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.

Webpack extensions configuration is ignored

See original GitHub issue

When using it like this, in a project that contains typescript files (.tsx compiles to .jsx)

const UniversalComponent = universal(({ page }) => import(`./pages/${page}`), {
    minDelay: 500,
    loading: Loading,
    error: Err
})

Webpack tries to bundle all the files in that directory, including the .tsx files, even though there is no loader defined for it and the extensions is defined as

    resolve: {
        extensions: ['.jsx', '.js', '.sass', '.scss'],
    },

To ignore the compile errors, I temporarily added the ignore-loader for .tsx files. Is there a way to configure this behaviour. Should I open this issue on webpack?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Kurounincommented, Sep 25, 2017

After having a look at ContextModule, it seems webpack tries to load a dependency first without an extension (./Home), then with the extensions found in that folder (./Home.jsx, ./Home.tsx).

When using ContextReplacementPlugin regex option to filter the dependencies that are loaded I was left only with ./Home.jsx which resulted in a chunk named pages/Home-jsx that couldn’t be used.

To workaround the issue I modified the regex to keep only the dependency without an extension (which actually resolves to the .jsx file according to my webpack config):

        new webpack.ContextReplacementPlugin(
            /^\.\/pages$/,
            /[^.]{4}$/
        ),

Using the above regex I get the desired outcome

                Asset       Size  Chunks                    Chunk Names
        pages/Home.js    39.7 kB       0  [emitted]         pages/Home
      pages/Market.js    2.66 kB       1  [emitted]         pages/Market
    pages/NotFound.js    1.21 kB       2  [emitted]         pages/NotFound
              main.js    2.72 MB       3  [emitted]  [big]  main

Thanks for guiding me in the right direction.

0reactions
faceyspaceycommented, Sep 25, 2017

glad to hear it! …been recommending this approach for a while, and you’re the first to finally prove it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack ignores webpack.config.js - Stack Overflow
It's odd that using a webpack.config.js file in your project root isn't working. Check this webpack-demo project. I think it can help you...
Read more >
IgnorePlugin - webpack
The following will cause those locale files to be ignored: new webpack.IgnorePlugin({ resourceRegExp: /^\.\/locale$/, contextRegExp: /moment$/, });.
Read more >
Webstorm is ignoring module resolution rules in webpack ...
02:15 Can't analyse client.config.dev.ts: coding assistance will ignore module resolution rules in this file. Possible reasons: this file is not a valid ...
Read more >
How to use the @expo/webpack-config/plugins ... - Snyk
plugin as any; // Replace HTML Webpack Plugin so we can interpolate it // @ts-ignore: webpack version mismatch config.plugins.splice(plugin.index, 1, new ...
Read more >
Custom Webpack Config - Next.js
The webpack function is executed twice, once for the server and once for the client. This allows you to distinguish between client and...
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