Solution 1 isn't great because on big maps the Pathfinding behavior will be quite slow.
If your game is grid-based, you can try EasyStarJS behavior, it's much faster. But still will probably struggle if your map is 100000x100000 tiles in size.
One workaround is to use an invisible tilemap, which you center on the player position and mark all obstacles on it. Then use EasyStarJS to find the path.