Open justinfagnani opened 11 months ago
Use one of these:
https://www.unpkg.com/browse/mobx@6.12.0/dist/
package export conditions
I am not up to date how "wide" the support is or what is or isn't possible. If you can guarantee it will work well with various setups, won't break existing uses and provide appropriate documentation, PR welcome.
Intended outcome:
The
mobx
module load in a browserActual outcome:
mobx.esm.js
throws an error:How to reproduce the issue:
Use any system that loads modules directly to the browser, such as unpkg.com, jsDelivr, the lit.dev playground, etc.
The import something from mobx, like:
This is due to this line in
errors.ts
:Presumably that comes from this source line:
but I can't see where
__DEV__
is defined.See this lit.dev playground reproduction:
https://lit.dev/playground/#gist=683ed61114ad2a20430fc8b1cc8229c8
You can get this working by defining
window.process.env
before loading the main script, but many users do not know to do that and get stuck.Versions
6.12.0
Potential Solutions
Previous issues (https://github.com/mobxjs/mobx/issues/2564) have been closed due to bundlers using
process.env.NODE_ENV !== "production"
for optimization. This shouldn't be necessary anymore with wide support for Node package export conditions. Packages can publish separate builds fordefault
anddevelopment
conditions and tools will pick the correct build.It's relatively easy to make these separate builds. Packages can define constants (like
const __DEV__ = true
) that are replaced in the default (prod) build to befalse
. The a tool like Rollup + Terser can do constant folding and dead code elimination to remove any code gated byif (__DEV__)
, etc.