question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ES6 module build includes references to `process.env.NODE_ENV`

See original GitHub issue

Describe 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:

  1. Use Rollup to create an ES6 module build that runs in the browser.
  2. Pass register to the ref prop as done in just about every example.
  3. Run the code in the browser.
  4. 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:closed
  • Created 3 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
jorisrecommented, Nov 22, 2020

👋🏻

@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 😉

1reaction
jorisrecommented, Jan 17, 2021

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_exports

We use exports too for resovlers but not for modern https://github.com/react-hook-form/resolvers/pull/108/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R11

Is it more clear ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possibility about conditional export ES6 module based on ...
I've found out the answer by myself, I think the best way to do this is through babel macros : import { something...
Read more >
How to Read Environment Variables in Node.js Using process ...
The process module has the env property that contains all the environment variables. To set an environment variable on Windows, you use the...
Read more >
Working with Environment Variables in Node.js - Twilio
Environment variables are a great way to configure parts of your Node.js application. Learn how to work with them using helpful tools such ......
Read more >
Managing Front-end JavaScript Environment Variables
The main .env file usually contains production variables while other ... the JavaScript where it will look up any references to process.env.
Read more >
Module Methods - webpack
Version 2 of webpack supports ES6 module syntax natively, meaning you can use import and export without a tool like babel to handle...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found