Skip to content

Resolve browser compatibility and circular import issues#167

Merged
zxwild merged 1 commit intogeoman-io:masterfrom
DeliaStrat:fix-env
Mar 4, 2026
Merged

Resolve browser compatibility and circular import issues#167
zxwild merged 1 commit intogeoman-io:masterfrom
DeliaStrat:fix-env

Conversation

@lhapaipai
Copy link
Contributor

Hi πŸ‘‹

When consuming maplibre-geoman directly from sources (e.g. as a git submodule, without a prior build step), two runtime issues arise.

Changes

constants.ts β€” Guard process access in browser environments

process.env.VITE_GEOMAN_VERSION throws a ReferenceError in the browser since process is not defined outside of Node/Vite-shim contexts. The existing try/catch only handled the case where __GEOMAN_VERSION__ is undefined, not where process itself is absent.

// before
geomanVersion = (process.env.VITE_GEOMAN_VERSION as GeomanVersion) || null;

// after
geomanVersion = ((typeof process !== "undefined") && process.env.VITE_GEOMAN_VERSION as GeomanVersion) || null;

style.ts β€” Circular dependency caused by @/main.ts import

Importing FeatureShape, LayerStyle and SOURCES from @/main.ts (the package entry point) creates a circular module graph that causes an infinite loop at runtime. Each symbol is now imported directly from its source module.

// before
import { type FeatureShape, type LayerStyle, SOURCES } from '@/main.ts';

// after
import { type LayerStyle } from '@/types/map/layers.ts';
import { SOURCES } from '@/core/features/constants.ts';
import { type FeatureShape } from '@/types/features.ts';

@zxwild zxwild merged commit c196fea into geoman-io:master Mar 4, 2026
7 checks passed
@zxwild
Copy link
Contributor

zxwild commented Mar 4, 2026

Ok, thanks, it seems it required to check such imports across the project. IDE tries to auto-import everything from main.ts for some reason.

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.

2 participants