#4520·mobx

Need tree-shaking import for the enableStaticRendering() function

Author: heath-freenomeCreated Feb 11, 2025Updated May 8, 2025
Labels🐛 bug

I am using NextJS and am calling the enableStaticRendering() function on the server. I currently have to import the function as follows:

typescript
import { enableStaticRendering } from 'mobx-react';

Due to the way NextJS deals with imports while building their production mode, I am getting the following warnings:

./node_modules/scheduler/cjs/scheduler.production.min.js
A Node.js API is used (setImmediate at line: 11) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime

Import trace for requested module:
./node_modules/scheduler/cjs/scheduler.production.min.js
./node_modules/scheduler/index.js
./node_modules/react-dom/cjs/react-dom.production.min.js
./node_modules/react-dom/index.js
./node_modules/mobx-react-lite/es/utils/reactBatchedUpdates.js
./node_modules/mobx-react-lite/es/index.js
./node_modules/mobx-react/dist/mobxreact.esm.js
./node_modules/@freenome/nextjs/esm/containers/ClientPageContainer/index.js
./node_modules/@freenome/nextjs/esm/index.js

./node_modules/scheduler/cjs/scheduler.production.min.js
A Node.js API is used (setImmediate at line: 11) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime

Import trace for requested module:
./node_modules/scheduler/cjs/scheduler.production.min.js
./node_modules/scheduler/index.js
./node_modules/react-dom/cjs/react-dom.production.min.js
./node_modules/react-dom/index.js
./node_modules/mobx-react-lite/es/utils/reactBatchedUpdates.js
./node_modules/mobx-react-lite/es/index.js
./node_modules/mobx-react/dist/mobxreact.esm.js
./node_modules/@freenome/nextjs/esm/containers/ClientPageContainer/index.js
./node_modules/@freenome/nextjs/esm/index.js

Actual outcome:

When I do try to import directly from the source file to avoid the error like in this screenshot, I get typescript issues:

Image

How to reproduce the issue:

I'm imagining, since there are so few static rendering functions in mobx-react-lite that if one were to update the package.json to add the exports section to provide a named export for the static rendering functions in then I could do what I needed. I am fairly confident that this change can be easily done in a backwards-compatible manner meaning that I could also import enableStaticRendering from the mob-react-lite as before.

Given that, I really can't provide an easily reproducible case for you unless you want me to link an entire nextjs application that is importing and using this function.

Versions "mobx": "6.13.6", "mobx-react": "9.2.0",