Skip to content

Commit fc4e377

Browse files
gtm-nayanPuruVJ
andauthored
fix: handle object browser field (#511)
* fix: handle object browser field * whoops * Add changeset --------- Co-authored-by: Puru Vijay <[email protected]>
1 parent 371ac4b commit fc4e377

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.changeset/slow-buckets-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/repl': patch
3+
---
4+
5+
(fix) Make mapbox work by properly resolving fields

packages/repl/src/lib/workers/bundler/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,21 @@ async function resolve_from_pkg(pkg, subpath, uid, pkg_url_base) {
185185

186186
// legacy
187187
if (subpath === '.') {
188-
const resolved_id = resolve.legacy(pkg, {
188+
let resolved_id = resolve.legacy(pkg, {
189189
fields: ['browser', 'module', 'main']
190190
});
191191

192+
if (typeof resolved_id === 'object' && !Array.isArray(resolved_id)) {
193+
const subpath = resolved_id['.'];
194+
if (subpath === false) return 'data:text/javascript,export {}';
195+
196+
resolved_id =
197+
subpath ??
198+
resolve.legacy(pkg, {
199+
fields: ['module', 'main']
200+
});
201+
}
202+
192203
if (!resolved_id) {
193204
// last ditch — try to match index.js/index.mjs
194205
for (const index_file of ['index.mjs', 'index.js']) {

0 commit comments

Comments
 (0)