添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

Bug Report

When using export * from './empty' where empty is an empty module I get an error that the file is not a module.

// index.ts
export * from './empty';

and two empty files empty.d.ts and empty.js next to it.

🔎 Search Terms

  • "TS2306"
  • export * with empty module
  • "is not a module"
  • 🕗 Version & Regression Information

    Happens in 4.4.4, and on all workbench versions.

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "'export *' with empty modules".
  • ⏯ Playground Link

    Workbench link with relevant code

    💻 Code

    // @filename: index.ts
    export * from './empty'
    // @filename: empty.d.ts
    // Comment.
    // @filename: empty.js
    // Comment.

    🙁 Actual behavior

    Error:

    error TS2306: File 'empty.d.ts' is not a module
    

    I can import empty modules, so why can't I export * from empty files?

    🙂 Expected behavior

    The export * should just be ignored, since the empty module doesn't export anything.

    This happens because TS treats files without any imports or exports as script code, not module code. The error should go away if you put export {} in the empty file.

    https://www.typescriptlang.org/docs/handbook/2/modules.html#how-javascript-modules-are-defined

    I can't easily do that, as the javascript/typescript files are generated by the protobuf compiler.
    But I agree that the behavior seems to defined in the documentation.
    Not really sure what to do. Maybe I should file a bug against the protobuf compiler...