env is hardcoded to "production" which causes React v17 to fail building properly
#1,721 opened on 2020年11月30日
Repository metrics
- Stars
- (11,091 stars)
- PR merge metrics
- (PR metrics pending)
説明
Current behavior
I think there's a mismatch of environment variables being read by babel (JSX config) and Styleguidist, causing some issues deeper down.
(I've noticed this was raised before but was closed)
- build.js sets the env to be
productionhere: https://github.com/styleguidist/react-styleguidist/blob/master/src/scripts/build.ts#L9 - This check is redundant because it will always be true, as env is hardcoded from the call above https://github.com/styleguidist/react-styleguidist/blob/master/src/scripts/make-webpack-config.ts#L31
- Again, env is hardcoded to production and then passed through here https://github.com/styleguidist/react-styleguidist/blob/master/src/scripts/make-webpack-config.ts#L131
So the issue is. My webpack config has mode set to "production" (because mode comes from env) and anything else that uses NODE_ENV will see developement.
I ended up with this error:
ReferenceError: _jsx is not defined.
I don't know why its hardcoded to production regardless of what you set, but it seems to be the cause of this bug.
Potential Fix https://github.com/styleguidist/react-styleguidist/blob/master/src/scripts/make-webpack-config.ts#L29 should be
env = process.env.NODE_ENV || env
https://github.com/styleguidist/react-styleguidist/blob/master/src/scripts/build.ts#L9 should also default to 'development' instead of 'production'