Closed lb- closed 5 years ago
Hi! Sorry for the delayed reply, and thank you for filing this issue.
I agree that prop-types should not be required in production. The code on master linked above is for Neutrino 9, whereas Neutrino 8 didn't use babel-plugin-transform-react-remove-prop-types
- see the v8 release branch:
https://github.com/neutrinojs/neutrino/blob/release/v8/packages/react/index.js
ie: Stripping prop-types is a new feature in Neutrino 9, which is currently in release candidate (see #1129) and I'd recommend using it over Neutrino 8 even before the final release :-)
@edmorley - epic news! thank you.
I am doing a blog post about using Neutrino and will try to upgrade my code to use v9 locally to see if it all works as expected.
Bug
What did you do?
<script src="/static/HelloWorld.js"></script>
window.React
What did you expect to happen?
The HelloWorld react component should mount on the #root div
What actually happened, contrary to your expectations?
require
is not defined see #1425 - this issue is NOT about the require being needed.I expected that prop-types are stripped from the build because of this code, which react-components uses: https://github.com/neutrinojs/neutrino/blob/master/packages/react/index.js#L28
Instead, I think what is happening is that that the webpack-node-externals is somehow thinking that the project needs prop-types because of its default behaviour call when used here:
https://github.com/neutrinojs/neutrino/blob/master/packages/react-components/index.js#L63
I think the actual prop-types are being stripped, but maybe that happens AFTER the
require
calls are added in the build process. I do not really know enough about webpack to know for sure but if I skip that step and define my own externals via a custom preset at the end, prop-types is not required.Work around + potential source of the problem
This code below solves the 'require' problem but as an aside, overriding the output in config.externals that is set by webpack-node-externals seems to resolve the issue of prop-types being expected to be available.
eg.