Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tobio89 opened this issue Dec 10, 2024 · 8 comments
Open

Comments

@Tobio89
Copy link

Tobio89 commented Dec 10, 2024

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

@Tobio89
Copy link
Author

Tobio89 commented Dec 10, 2024

btw the TSConfig it's using looks like this:

{
  "extends": "../../tsconfig.build.json",
  "compilerOptions": {
    "incremental": true,
    "target": "ESNext",
    "module": "ESNext",
    "outDir": "./dist",
    "rootDir": "./src",
    "baseUrl": ".",
    "jsx": "react",
    "lib": ["DOM", "ESNext"],
    "composite": true,
    "declaration": true,
    "typeRoots": ["./node_modules/@types", "./src/@types", "./src/types"]
  },
  "include": ["src/**/*"],
  "references": []
}

and the extended file looks like this:

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "noEmit": false,
    "noEmitOnError": true
  }
}

@rschristian
Copy link
Collaborator

A reproduction would be helpful, are you using microbundle or microbundle-crl? This sounds like an issue the latter would cause.

@Tobio89
Copy link
Author

Tobio89 commented Dec 10, 2024

We're just using microbundle. I can try to put a repro repository together if that will help.

@rschristian
Copy link
Collaborator

A repro is always helpful and almost always necessary.

I can't reproduce so will definitely need a minimal reproduction. Babel shouldn't be running against .d.ts files at all, not quite sure how you've done that.

@Tobio89
Copy link
Author

Tobio89 commented Dec 10, 2024

I tried to reproduce it in another project but it hasn't happened yet :S

@Tobio89
Copy link
Author

Tobio89 commented Dec 10, 2024

What's more, I removed the babelrc file from the actual project, and it built as normal. I'll fiddle with it a bit more and see if it breaks again, and if not... false alarm 😅

@rschristian
Copy link
Collaborator

No worries, feel free to ping if/when you do find something out.

One thing that might be worth trying is uninstalling & reinstalling microbundle into your project. Sometimes transitive deps (dependencies of dependencies) get stuck on odd & bugged versions, reinstalling tends to fix that.

@Tobio89
Copy link
Author

Tobio89 commented Dec 10, 2024

It might also be that it was getting stuck on this babel issue with 0.14.x, and then by upgrading, it went away but the .babelrc file was then causing the other issue to remain. Hmm...

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

No branches or pull requests

2 participants