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.

Inconsistency with Webpack v4

See original GitHub issue

So when using dynamic imports with Webpack v4, Webpack is now using a namespace object.

https://github.com/webpack/webpack/releases/tag/v4.0.0 https://medium.com/webpack/webpack-4-import-and-commonjs-d619d626b655

This matches what is done when you use ESM modules and you import Commonjs. You have to reference “default” now in Webpack v4 when attempting to reference module.exports. This is not the same as doing a deferred require on the server. My workaround has been to do something akin to this

const EXIFModule = await import(/* webpackChunkName: "exif-js" */ 'exif-js');
// Gets around dynamic import inconsistencies between browser and server
const EXIF = EXIFModule.default || EXIFModule;

Ideally, there would be some way to at least have a setting for this plugin to turn on namespace object dynamic imports.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:16

github_iconTop GitHub Comments

6reactions
jljorgenson18commented, Apr 7, 2018

Maybe I’m not being clear but I am not saying we need to drop everything and conform to Webpack v4 because there is no other use case. I am saying that Webpack is used much more than Rollup and Browserify (https://stateofjs.com/2017/build-tools/results) and that this is a legitimate issue. My suggestion would be to add a config option in babel for a slightly different require to handle both cases if you are using Webpack v4. Is there anything specific that I am saying that you think is false?

3reactions
jljorgenson18commented, Apr 7, 2018

It is my understanding that the purpose of this plugin is to take Javascript code that uses a dynamic import and then have that code run with Node.js. The primary reason somebody would be using a dynamic import is for use with Webpack. Then, they may want to run that same Webpack code in a test or on a server with isomorphic Javascript which is where this plugin comes in to help. I’m not attempting to be argumentative, but this inconsistency is going to cause problems for people that are trying to reuse Webpack code in Node.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack version inconsistency after npm update #911 - GitHub
Steps to reproduce · Install latest version · Downgrade another package · Run npm update · Run npm run start or npm run...
Read more >
Inconsistent mainFields resolution using Webpack 4 in a ...
In a monorepo that is wired using Lerna and Yarn workspaces, one of the packages is a Next.js app, which depends on several...
Read more >
The Problem with Webpack and Why It Is (Kind of) Our Fault
It wants to be batteries-included but pluggable, standalone but extensible, everything you need out of the box but extensible. By merging both ...
Read more >
How I solved and debugged my Webpack issue through trial ...
When webpack bundles your source code, it can become difficult to track down errors and warnings to their original location.
Read more >
Build Performance - webpack
Webpack 4 outputs a large amount of data with its stats. ... The following tools have certain problems that can degrade build performance: ......
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