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 5] webpack dev server client entry is being returned instead of the main entry when outputting a library. #2719

Closed
dmitrysteblyuk opened this issue Aug 23, 2020 · 6 comments

Comments

@dmitrysteblyuk
Copy link

Bug report

What is the current behavior?
When building a library in dev mode (via webpack-dev-server) the dev server client is being returned as a library (which is actually an empty object as the client does not export anything).

If the current behavior is a bug, please provide the steps to reproduce.
Use library: 'MainLib' for example and run npx webpack-dev-server.
Observe returned library is an empty object.
Running npx webpack does not have this issue.

Repro:

https://github.com/dmitrysteblyuk/webpack-entry-point-bug-repro

When you run npx webpack-dev-server you can check the ./dist/main.js..
It will be like this (dev client entry is returned):

/******/  // module exports must be returned from runtime so entry inlining is disabled
/******/  // startup
/******/  // Load entry module and return exports
/******/  __webpack_require__("./main-entry.js");
/******/  return __webpack_require__("./node_modules/webpack-dev-server/client/index.js?http://localhost:8080");
/******/ })()
;

What is the expected behavior?
The provided main entry is returned as a library.

Other relevant information:
webpack version: ^5.0.0-beta.28
Node.js version: v13.12.0
Operating System: Mac OS X 10.15.5
Additional tools:
webpack-dev-server: ^3.11.0
webpack-cli: ^3.3.12

@alexander-akait alexander-akait transferred this issue from webpack/webpack Aug 24, 2020
@alexander-akait
Copy link
Member

Feel free to send a PR

@dmitrysteblyuk
Copy link
Author

I managed to make it work when I moved addEntries from updateCompiler to before webpack compiler is instantiated (in ./bin/webpack-dev-server.js).
So apparently changing entry option after initialization is not okay with webpack 5 anymore.
I understand it's not a solution since it will only work when running dev server from cli (and Server accepts webpack compiler as an argument - so it's late to change entries at this point).
I'd welcome any ideas on how to make it work with both cli and api.
Or maybe just moving this bug to wepback after all, bc it used to work fine.

@alexander-akait
Copy link
Member

Can you try #2699?

@dmitrysteblyuk
Copy link
Author

Can you try #2699?

It's wrong to prepend original entry points to additional ones like done in this pr.
Bc webpack exports the last entry point in case of library.
But I did check it anyways and it's indeed broken for both webpack 5 and 4.

@ylemkimon
Copy link
Contributor

Possible duplicate of #2484?

@dmitrysteblyuk
Copy link
Author

Possible duplicate of #2484?

Indeed it is.

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

No branches or pull requests

3 participants