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

[BUG]: Broken API (0.5.58 → 0.5.64) : ERROR TS2307 - Cannot find module 'xxx' or its corresponding type declarations #2080

Open
Mara-Li opened this issue Sep 30, 2023 · 10 comments
Labels
bug Something isn't working.

Comments

@Mara-Li
Copy link

Mara-Li commented Sep 30, 2023

What happened?

When updating in my own plugin the dataview package to 0.5.59, TS can't found any declaration for Obsidian-dataview.

image

Translation:

Try npm i --save-dev @types/obsidian-dataview if it exists or add a new declaration (.d.ts) file containing `declare module 'obsidian-dataview';
ERROR TS7016 Could not find a declaration file for module 'obsidian-dataview" […]

Spotted that the two last version doesn't have the main.d.ts file:

Comparison to 0.5.56, where libs contains everything.

DQL

/

JS

No response

Dataview Version

0.5.58 - 0.5.56

Obsidian Version

Not relevant

OS

Windows

@Mara-Li Mara-Li added the bug Something isn't working. label Sep 30, 2023
@Mara-Li Mara-Li changed the title [BUG]: Broken API (0.5.58 - 0.5.59) [BUG]: Broken API (0.5.58 - 0.5.59) : Could not find a declaration file for module Sep 30, 2023
@Mara-Li Mara-Li changed the title [BUG]: Broken API (0.5.58 - 0.5.59) : Could not find a declaration file for module [BUG]: Broken API (0.5.58 - 0.5.59) : ERROR TS7016 - Could not find a declaration file for module Sep 30, 2023
@Mara-Li
Copy link
Author

Mara-Li commented Oct 6, 2023

Updating to 0.5.60 should help, but now, any import lead to "any" and opening the index.d.ts & other files leads to that :

image

Error (TS2307)
error TS2307: Cannot find module 'xxxx'

My tsconfig:

{
  "compilerOptions": {
    "baseUrl": "./",
    "inlineSourceMap": true,
    "inlineSources": true,
    "module": "ESNext",
    "target": "ES6",
    "allowJs": true,
    "noImplicitAny": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "isolatedModules": true,
    "resolveJsonModule": true,
    "strict":true,
    "lib": [
      "DOM",
      "ES5",
      "ES6",
      "ES7",
      "ES2021",
      "ES2022"
    ],
  },
  "include": [
    "**/*.ts"
  ]
}

@Mara-Li Mara-Li changed the title [BUG]: Broken API (0.5.58 - 0.5.59) : ERROR TS7016 - Could not find a declaration file for module [BUG]: Broken API (0.5.58 - 0.5.59 - 0.5.60) : ERROR TS7016 - Could not find a declaration file for module Oct 6, 2023
@Mara-Li Mara-Li changed the title [BUG]: Broken API (0.5.58 - 0.5.59 - 0.5.60) : ERROR TS7016 - Could not find a declaration file for module [BUG]: Broken API (0.5.58 → 0.5.60) : ERROR TS7016 - Could not find a declaration file for module Oct 6, 2023
@Mara-Li
Copy link
Author

Mara-Li commented Oct 27, 2023

Bug remains in 0.5.61

@Mara-Li Mara-Li changed the title [BUG]: Broken API (0.5.58 → 0.5.60) : ERROR TS7016 - Could not find a declaration file for module [BUG]: Broken API (0.5.58 → 0.5.61) : ERROR TS7016 - Could not find a declaration file for module Oct 27, 2023
@Mara-Li
Copy link
Author

Mara-Li commented Nov 5, 2023

Remains in 0.5.64

@Mara-Li Mara-Li changed the title [BUG]: Broken API (0.5.58 → 0.5.61) : ERROR TS7016 - Could not find a declaration file for module [BUG]: Broken API (0.5.58 → 0.5.64) : ERROR TS7016 - Could not find a declaration file for module Nov 5, 2023
@Mara-Li Mara-Li changed the title [BUG]: Broken API (0.5.58 → 0.5.64) : ERROR TS7016 - Could not find a declaration file for module [BUG]: Broken API (0.5.58 → 0.5.64) : ERROR TS2307 - Cannot find module 'xxx' or its corresponding type declarations Nov 5, 2023
@Mara-Li
Copy link
Author

Mara-Li commented Nov 5, 2023

image

@cfilipov
Copy link

I'm having the same issue. I did a fresh clone of the obsidian-sample-plugin repo and followed the instruction for adding the dataview api to the plugin and getting the same problems listed above.

@cfilipov
Copy link

cfilipov commented Dec 2, 2023

As @Lisandra-dev pointed out this was broken after 0.5.56. From what I can see, in the following release, a dependency on ttypescript was removed and a misconfiguration in the rollup.config.js caused types to go missing (#2073) for few releases until it was fixed in 0.5.60 (#2074). However, from 0.5.60 and onwards the imports in the generated d.ts files are no longer relative paths, causing module resolution to fail resulting in importing those types as any as shown above.

Note the difference between the imports in index.d.ts (0.5.56) vs index.d.ts (0.5.60).

As a temporary workaround I manually edited the imports in the d.ts files in node_modules to use relative imports and that resolved the issue. Of course this will revert to the error when you wipe node_modules or do a clean install.

I don't know what a real fix to this would be. I'm assuming the removal of ttypescript had something to do with it but I'm not familiar with that package. Perhaps setting paths in tsconfig-lib.json?

@Mara-Li
Copy link
Author

Mara-Li commented Dec 2, 2023

My methods to fix this on my side:
https://github.com/ObsidianPublisher/obsidian-github-publisher/blob/e2e3738541d0188ae0f90397837395ee0c8f2a0b/tsconfig.json#L4-L10

@dstengle
Copy link

I needed to make additional paths beyond the above but now I'm down to an error about LocalForage. I'm just trying to use in node, not an obsidian plugin.

@Mara-Li
Copy link
Author

Mara-Li commented Feb 26, 2024

Any update…?

@mnaoumov
Copy link
Contributor

mnaoumov commented Jun 9, 2024

I've got some workarounds

tsconfig.json

{
  "compilerOptions": {
    "paths": {
      "*": [
        "./node_modules/obsidian-dataview/lib/*"
      ]
    }
}

Regarding LocalForage issue, it's solved by adding somewhere in your code

import "localforage";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

4 participants