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

Error: Unexpected token when including a file with `declare namespace` in it.

未关闭
#1,088 8 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
babel, javascript, typescript

调研方向

使用所引用的 OpenSeadragonV5.d.ts 文件复现报告中的命令 microbundle --jsx React.createElement --tsconfig tsconfig.build.json。首先检查 tsconfig.build.json.babelrc.json,了解声明文件和 declare namespace 是如何解析的。完成的标准是 package 构建时不会出现意外 token 或 Babel 语法错误。

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

描述

Hi microbundle team.

I'm trying to build a package, and I've needed to override some types since the types repo for the main dependency hasn't been updated.
I was on 0.14.x before, but I updated to 0.15.1 and I still get this error.

$ microbundle --jsx React.createElement --tsconfig tsconfig.build.json
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

at /Users/user/Documents/osd-react-renderer/packages/renderer/src/types/OpenSeadragonV5.d.ts:3:8

1: /* eslint-disable max-classes-per-file */
2: 
3: declare namespace OpenSeadragon {
           ^
4:     export function isFunction(obj: unknown): boolean;

I actually had two errors in this file. The first error said:

osd-react-renderer: (babel plugin) SyntaxError: /Users/user/Documents/osd-react-renderer/packages/renderer/src/types/OpenSeadragonV5.d.ts: Missing semicolon. (3:7)
osd-react-renderer:   1 | /* eslint-disable max-classes-per-file */
osd-react-renderer:   2 |
osd-react-renderer: > 3 | declare namespace OpenSeadragon {
osd-react-renderer:     |        ^
osd-react-renderer:   4 |     export function isFunction(obj: unknown): boolean;
osd-react-renderer:   5 |
osd-react-renderer:   6 |     export function isCanvasTainted(canvas: HTMLCanvasElement): boolean;
osd-react-renderer: at undefined:3:7

This error I was able to resolve with a .babelrc.json file, but I can't see what configuration can be used to resolve the first error.

I noticed that previously we were able to build the app when we used declare module OpenSeadragonV2, but declare namespace` specifically is causing this.

Any suggestions on what configuration can resolve this issue?

Thanks

主要语言
JavaScript
星标
8.1k
派生
358
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

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

developit/microbundle 的其他 Issue

查看 developit/microbundle 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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