Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack compiling twice on startup when importing a file within a typescript react setup #14768

Closed
bahtou opened this issue Nov 18, 2021 · 8 comments · Fixed by #14777
Closed

Comments

@bahtou
Copy link

bahtou commented Nov 18, 2021

Bug report

What is the current behavior?

Working on a TypeScript React project when running webpack the compilation happens twice at startup. This happens when a file is being imported from the root react index.tsx.
Not sure if its similar to #13618?

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

  1. https://github.com/bahtou/issues/tree/webpack-rebuild
  2. follow the readme

you should be able to see two rebuilds

👀   1 . compilation afterEmit 2021-11-18T22:01:58.573Z
👀   1 . compilation is done 2021-11-18T22:01:58.575Z
👀   2 . compilation afterEmit 2021-11-18T22:01:58.872Z
👀   2 . compilation is done 2021-11-18T22:01:58.872Z

What is the expected behavior?

compilation should only run once

Other relevant information:
webpack version: 5.64.1
Node.js version: v14.18.1
Operating System: OSX
Additional tools: none

@bahtou bahtou changed the title webpack compiling twice on file import in typescript react setup webpack compiling twice on startup when importing a file within a typescript react setup Nov 18, 2021
@markjm
Copy link
Contributor

markjm commented Nov 18, 2021

I think this is related to #14735.

The invalidation comes from

_invalidate(..., ..., Set(0) {} Set(2) {
  '/workspaces/issues/node_modules/package.json/package.json',
  '/workspaces/issues/node_modules/swc-loader.js/package.json'
}

This indicated that watchpack.watch is called with these invalid file entries. When encountering these paths, it then tries to adds watchers for these files, fails (because they dont exist "initial-missing / scan (parent directory missing in initial scan)") and marks them as removed.

@wood1986
Copy link
Contributor

wood1986 commented Nov 19, 2021

I think it has nothing with TS. My JS repo has the same issue and it compile 3 times.
I can 120% confirm 5.64.0 work fine and it only happen at 5.64.1

@bahtou
Copy link
Author

bahtou commented Nov 19, 2021

@wood1986 I switched to webpack v5.64.0 and I still get the double compilation. With the repo above you can test it out. Agree that it has nothing to do with TS. The webpack config is not using TS for anything. I just mentioned it since I was setting up a new project.

@alexander-akait
Copy link
Member

Yep, it is bug

@alexander-akait
Copy link
Member

@bahtou v5.64.0 doesn't have this problem, just tested on your repo

@bahtou
Copy link
Author

bahtou commented Nov 19, 2021

@alexander-akait I just cloned the repo and updated the webpack package to 5.64.0.
I'm still getting double compilation 🤔 🤔

rm -rf node_modules package-lock.json
npm install
npm start

UPDATE
"webpack": "^5.64.0", the caret ^ was throwing me off. Removing the ^.

v5.64.0 DOES NOT have the issue. 👍🏽

@alexander-akait
Copy link
Member

Yep...

@sokra
Copy link
Member

sokra commented Nov 20, 2021

should be fixed by https://github.com/webpack/webpack/releases/tag/v5.64.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants