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

Combining preact and with-jest examples results in production build error #1545

Closed
timmywil opened this issue Mar 28, 2017 · 3 comments
Closed

Comments

@timmywil
Copy link
Contributor

timmywil commented Mar 28, 2017

Example: I've updated the with-jest example to also include preact to reproduce this issue.

Essentially, react-test-renderer relies on a private file in react that isn't present in preact. When bundling for production, that file obviously isn't present. However, there's no point in bundling anything in a __tests__ folder as none of that will get served in production.

This used to work fine in 2.0.0-beta.41, but I think the 2 webpack commits in 2.0.0-beta.42 exposed the fact that the __tests__ directories are being included in the loaders when bundling for production. I was using config.externals in my next.config.js, but I think the new chunk plugin addition isn't respecting that option somehow. If this can be resolved through webpack config, I would welcome any suggestions.

I think one solution would be to exclude directories matching /\/(?:__)?test/ or something in the default webpack config in next.js.

@timmywil
Copy link
Contributor Author

I figured out that setting config.externals to ['react-test-renderer'] prevents the error, but JS files in the pages/__tests__ directory are still bundled as if they were pages.

@timmywil
Copy link
Contributor Author

OK, I don't think there's a good solution to this on your end. I worked around it by moving pages/__tests__ to the top-level directory and ensuring that all files within pages were actually bundle-able. The config.externals option also becomes unnecessary at that point.

I'll close this, but I recommend documenting somewhere that even tests should not be placed in the pages directory.

@sedubois
Copy link
Contributor

Maybe better to keep issue open in that case :)

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

No branches or pull requests

2 participants