Skip to content

Conversation

@constayush
Copy link

@constayush constayush commented Dec 3, 2025

Problem

Importing motion-utils directly in the browser as a native ES module throws
ReferenceError: process is not defined.

This happens because process.env.NODE_ENV is accessed at module evaluation
time without guarding for non-Node environments. The issue is masked when usin
bundlers that inject a process polyfill, but fails in pure browser ESM

Solution

Guard access to process before reading process.env.NODE_ENV so the code can
run safely in browsers while preserving existing behavior for Node and bundler
environments.

Result

  • Native browser ES module imports no longer throw
  • No behavior change for production builds
  • No reliance on bundler polyfill

Fixes : #3417

@stefanpearson
Copy link

Thanks!

@stefanpearson
Copy link

stefanpearson commented Dec 3, 2025

I've noticed a few other 'unsafe' references to process.env across various files in the motion packages. I'm assuming they will need updating too? https://github.com/search?q=repo%3Amotiondivision%2Fmotion%20process.env&type=code

@constayush
Copy link
Author

constayush commented Dec 4, 2025

I dont think so as most of them are node only files so it should not be a problem , but yeah there are 'unsafe' references to process.env inside /src like Hooks, utils, render logic, that should be guarded as they ll be run in browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ReferenceError: process is not defined in native ES module usage

2 participants