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

commonjs output clashes with chunk splitting #7392

Closed
garthk opened this issue May 25, 2018 · 5 comments
Closed

commonjs output clashes with chunk splitting #7392

garthk opened this issue May 25, 2018 · 5 comments
Labels

Comments

@garthk
Copy link

garthk commented May 25, 2018

Bug report

What is the current behavior?

Attempting to use optimization.splitChunks.cacheGroups in combination with commonjs results in broken output packages, importing of which fails with:

TypeError: Cannot read property 'call' of undefined
    at __webpack_require__ (/Users/garthk/src/webpack-4-bug/build/index.js:20:30)

If there's a documented way to get the entry bundle build/index.js to inhale the split bundle build/vendors.js so its imports don't fail, please let me know where it is and I'll file a PR to make it easier to find.

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

git clone https://github.com/garthk/webpack-4-chunk-splitting-bug.git
cd webpack-4-chunk-splitting-bug
cat README.md
npm install
node_modules/.bin/webpack
node -p 'Object.keys(require("./build"))'

Note error:

/Users/garthk/src/webpack-4-bug/build/index.js:20
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
                              ^

TypeError: Cannot read property 'call' of undefined
    at __webpack_require__ (/Users/garthk/src/webpack-4-bug/build/index.js:20:30)

(modules has keys ./src/index.ts, crypto, tty, and util, and we're trying to find a moduleId of ./node_modules/uuid/index.js in there. No wonder it's failing. Anyhow; comment out the splitChunks block in webpack.config.js, try again, and note no error.

What is the expected behavior?

Being able to split the output into multiple files and require the entry point without failure.

Other relevant information:

webpack version: 4.8.3
Node.js version: 8.11.2
Operating System: macOS, Linux
Additional tools: none

@sokra
Copy link
Member

sokra commented May 25, 2018

target: "node" doesn't support splitChunks with chunks: "initial" or chunks: "all".

@alexander-akait
Copy link
Member

@sokra maybe we can output warning on this?

@ooflorent
Copy link
Member

@evilebottnawi It's a good idea. Also the documentation should be updated to reflect this limitation.

@webpack-bot
Copy link
Contributor

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

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

No branches or pull requests

5 participants