ES6 module build includes references to `process.env.NODE_ENV`
See original GitHub issueDescribe the bug
The ES6 module build includes references to process.env.NODE_ENV
, which breaks browser usages – browsers now support ES6 modules. This is hidden by react-scripts
in Codesandbox.io because it provides a definition for process.env.NODE_ENV.
To Reproduce Steps to reproduce the behavior:
- Use Rollup to create an ES6 module build that runs in the browser.
- Pass
register
to theref
prop as done in just about every example. - Run the code in the browser.
- Open the JS console and note the “process is not defined” error.
Codesandbox link (Required) I flipped a table trying to get Codesandbox to not use create-react-app. I hope you don’t mind if I just created a dedicated repo with reproduction instructions in the README:
https://github.com/spaceaardvark/react-hook-form-bug1
Expected behavior The browser build should not encounter or use process.env.NODE_ENV.
Desktop (please complete the following information):
- OS: Ubuntu 20
- Chrome
- v86.0.4240.198
Additional context From conversation in #1441 after it was closed.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (11 by maintainers)
👋🏻
@spaceaardvark Thanks for reporting. Your use case is really interesting ! Thanks for the reproduction. I think you mean modern module (es6) . At this time, RHF’s ES6 module is not a modern module, that’s why it contains
process.env.*
.@bluebill1049 Yes, this can be solved by using microbundle which provide modern bundle. I started to switch from custom rollup config to microbundle this morning 😉
I mean I don’t know where I have to add the modern bundle in the
exports
field of the package.json: https://nodejs.org/api/packages.html#packages_conditional_exportsWe use
exports
too for resovlers but not for modern https://github.com/react-hook-form/resolvers/pull/108/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R11Is it more clear ?