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 serve compiling twice with a specific dependency package.json

See original GitHub issue

Bug report

What is the current behavior?

Webpack is compiling the project twice, when running in serve mode, if the project imports a library with the following package.json main config:

"main": "./lib/",

If the current behavior is a bug, please provide the steps to reproduce.

  1. Open https://stackblitz.com/edit/webpack-double-compilation
  2. Run npm start
  3. Notice that compilation is run twice on start:
webpack 5.38.1 compiled successfully in 649 ms
...
webpack 5.38.1 compiled successfully in 54 ms

This will fix the problem:

  1. Open webpack.config.js
  2. Add the commented sdp-transform alias
  3. Run npm start again
  4. Notice that compilation is run once only:
webpack 5.38.1 compiled successfully in 588 ms 

You can also test this locally following this steps:

  1. Install sdp-transform as a dependency
  2. Import sdp-transform in an entry point
  3. Run webpack serve
  4. Notice that the compilation is now run twice

What is the expected behavior?

Compilation should only run once.

Other relevant information: webpack version: 5.38.1 and 5.37.1 Node.js version: v14.16.0 and v14.17.0 Operating System: stackblitz OS (?) and Windows 10 Additional tools: none

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:25 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
david10singcommented, Jun 1, 2022

I think I am experiencing the same issue with storybook webpack5 doing a build twice

1reaction
alexander-akaitcommented, Feb 2, 2022

I think resolver try to watch something wrong, I do not look it deeply, but if you change "main": "./lib/index.js" (i.e. index.js) all works fine, anyway using "main": "./lib/" is working in commonjs Node.js, because by default we try to load index.js in directly, it is very intresting, because no RFC or something else about it, it s just side effect built-in Node.js commonjs loader

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack serve compiling twice with a specific dependency ...
Webpack is compiling the project twice, when running in serve mode, if the project imports a library with the following package.json main config ......
Read more >
webpack-dev-server runs twice - Stack Overflow
I realised that I had webpack-dev-server package installed twice, one in my project folder node_modules since it was listed as dependency in my ......
Read more >
sass-loader - webpack - JS.ORG
The special implementation option determines which implementation of Sass to use. By default the loader resolve the implementation based on your dependencies.
Read more >
Serverless Webpack - Serverless Framework: Plugins
A Serverless Framework plugin to build your lambda functions with Webpack. ... must appear in your service's production dependencies in package.json .
Read more >
webpack Tutorial: How to Set Up webpack 5 From Scratch
the webpack-dev-server command is now webpack-serve ... In package.json , we can make a build script that runs the webpack command.
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