Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

web-bundle: a root-relative import from a remote plugin fails in the browser

已关闭 适合新手
#94 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript
领域
frontend

调研方向

从 apps/web-bundle/src/loader.js 开始,其中 loadRemoteModule 会跳过所有不是 ./ 或 ../ 的 specifier(即 isRelative 检查)。与 apps/cli/remote-loader.js 中的 Node 钩子进行比较,后者会相对于插件的 origin 解析根相对 specifier。完成的标准是:在浏览器中加载的插件里,像 /lib/x.js 这样的根相对导入会相对于模块的源 URL 进行解析,并通过 loadRemoteModule 加载;同时绝对的 https: specifier 保持不变,并且两个宿主的结果一致。

由索引模型根据 Issue 内容生成。

描述

bug

What happens

A remote plugin loaded in the browser whose own source imports a root-relative specifier (import x from '/lib/x.js') fails to load. The same plugin loads on Node.

Why

loadRemoteModule in apps/web-bundle/src/loader.js rewrites only ./ and ../ specifiers to their children's blob URLs; anything else is left for the browser (if (!isRelative(spec)) return null). The module itself runs from a blob: URL, and a blob: base cannot resolve any relative reference:

new URL('/x.js', 'blob:http://localhost:8080/0b6e-uuid')  // throws ERR_INVALID_URL

Node's hook (apps/cli/remote-loader.js) resolves a root-relative specifier against the plugin's origin, so the two hosts disagree.

Notes toward a fix

Treat a specifier starting with / (but not //) like a relative one: new URL(spec, url) against the module's source URL, then load it through loadRemoteModule. An absolute https: specifier must stay untouched, as now; that is what gives a CDN module its real URL as identity.

Found while reviewing #93.

主要语言
TypeScript
星标
5
派生
2
平均合并
9 小时 5 分钟
30 天内合并 PR
11

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MatAtBread/matbot 的其他 Issue

查看 MatAtBread/matbot 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。