question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to import declaration files with this plugin?

See original GitHub issue

I have a dependency with a single .ts source file that imports declarations from many .d.ts declaration files. When Rollup hits a declaration file, I get a PARSE_ERROR telling me that Rollup is trying to parse the TypeScript declaration file as an ES module. I tracked that down to the exclude setting for this plugin which skips .d.ts files by default. After setting exclude: [], this plugin parses the file, but whatever ES module it returns to Rollup is missing the declarations inside, because I get a MISSING_EXPORT error. Is there a way to see what ES module this plugin is returning for a given TS declaration file? Is there a way to get it to include all the exports in a declaration file?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ezolenkocommented, Jun 23, 2021

For rollup, the problem is that d.ts don’t contain any code that translate to java script – translated d.ts file is an empty js file.

Normally you are not supposed to import d.ts files directly, but let typescript find them itself (by setting types parameter in package, etc).

0reactions
agilgur5commented, May 27, 2022

Going to close this out as I believe this has been answered well and in entirety – declarations are indeed not supposed to be imported and indeed would not produce valid ES modules. That is TS behavior and not specific to this plugin.

OP also suggested themselves that the issue was not with this plugin and has not responded to further comments.

Note that triple-slash directives may behave differently, which may be what OP intended to do instead?

Read more comments on GitHub >

github_iconTop Results From Across the Web

A quick introduction to “Type Declaration” files and adding ...
The standard library (global type declaration) files are imported implicitly by the TypeScript compiler by looking at the lib compiler-option ( ...
Read more >
How to import js module when Typescript declaration file is ...
Create an empty folder and then run npm -y init · Run the following command: · Add "build": "rollup --config" to your package....
Read more >
Module: Plugin - TypeScript: Documentation
Some plugins add or modify top-level exports on existing modules. While this is legal in CommonJS and other loaders, ES6 modules are considered...
Read more >
TypeScript | IntelliJ IDEA Documentation - JetBrains
Add import statements on code completion · In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | General | Auto Import. The...
Read more >
rollup-plugin-ts - npm
Absolutely, even with Declaration files. Things will work seamlessly. Why wouldn't you use just TypeScript? The TypeScript compiler, while ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found