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

Bundle generation fails with Cannot find namespace 'Protocol' (but Protocol doesn't seem to be a global declaration) #237

Closed
d4h0 opened this issue Mar 5, 2023 · 5 comments · Fixed by #242
Assignees
Milestone

Comments

@d4h0
Copy link

d4h0 commented Mar 5, 2023

Hi,

I'm trying to generate a .d.ts bundle for Playwright, but unfortunately I get the following error message:

packages/playwright-core/bundle.d.ts(11923,23): error TS2503: Cannot find namespace 'Protocol'.

I've read Fixing compilation issues while using declare module or similar "global" type declarations, and this doesn't seem to apply here (however, I haven't used TypeScript much, so I might be wrong).

Protocol seems to be defined in packages/playwright-core/types/protocol.d.ts:

export module Protocol {
    // ...
}

...which is imported in packages/playwright-core/types/types.d.ts via import { Protocol } from './protocol';, which itself is re-exported from packages/playwright-core/index.d.ts and packages/playwright/index.d.ts.

I've noticed two things:

  1. packages/playwright-core/types/types.d.ts isn't in the src directory
  2. The error says namespace 'Protocol', not module 'Protocol'.

Could any of this be the issue?

In any case, the generated file doesn't contain the module definition of Protocol.

Do you have any idea, why this isn't working?

The following commands reproduce the issue:

git clone https://github.com/microsoft/playwright/
cd playwright/
npm i -D dts-bundle-generator
npx dts-bundle-generator -o  packages/playwright-core/bundle.d.ts packages/playwright/index.d.ts

PS: In case you are wondering, I'm trying to generate a .d.ts bundle for Playwright to generate language bindings for F# via ts2fable, which unfortunately doesn't handle re-exports (so I'd like to use dts-bundle-generator to generate a .d.ts file that ts2fable understands).

@timocov
Copy link
Owner

timocov commented Mar 5, 2023

The error says namespace 'Protocol', not module 'Protocol'.

This is what the compiler says. Internally "modules" are namespaces.

If you add --inline-declare-externals flag it seems to work fine. Meanwhile I'll look into why --inline-declare-externals affects such namespaces/modules.

@timocov
Copy link
Owner

timocov commented Mar 5, 2023

It seems that the issue is caused by this code and changing this might be a breaking change. I'll assign the issue to the next major milestone, meanwhile please use workaround with --inline-declare-externals flag.

@timocov timocov added this to the 8.0 milestone Mar 5, 2023
@timocov
Copy link
Owner

timocov commented Mar 5, 2023

Note for the future fix: this requires to check how the new generation works for Dexie.js.

@timocov timocov self-assigned this Mar 5, 2023
@d4h0
Copy link
Author

d4h0 commented Mar 5, 2023

Thanks, @timocov!

timocov added a commit that referenced this issue Mar 28, 2023
…quotes) and fixed wrong `export` state of references namespaces/modules

Previously, for some reason name `ModuleName` was treated the same as with quotes
i.e. it was checked whether that name should be exported.

Now every used module with such name will be inlined regardless of `--inline-declare-externals` option.

Fixes #237, #241
@timocov
Copy link
Owner

timocov commented Mar 30, 2023

Released in v8.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment