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]: Cannot find module 'topojson-specification' or its corresponding type declarations #1854

Closed
1 of 6 tasks
huineng opened this issue Jun 16, 2024 · 5 comments · Fixed by #1871
Closed
1 of 6 tasks

Comments

@huineng
Copy link

huineng commented Jun 16, 2024

Relevant package(s)

  • @carbon/charts
  • @carbon/charts-svelte
  • @carbon/charts-react
  • @carbon/charts-angular
  • @carbon/charts-vue
  • Documentation website

Carbon Charts Version

1.16.8

Which bundler are you using?

Webpack

What happened and what did you expect to happen?

I guess this is related to this change

import type { Topology } from 'topojson-specification'

the package dev dependencies are not install by npm (only the dependencies or unless i install them myself in my main package) (see this thread microsoft/types-publisher#81 (comment)

Is it possible to move @types/topojson to dependencies or to explicitly mention we have to install them

thanks

this was the error

ERROR in node_modules/@carbon/charts/dist/interfaces/charts.d.ts:1:26 - error TS2307: Cannot find module 'topojson-specification' or its corresponding type declarations.

1 import { Topology } from 'topojson-specification';
                           ~~~~~~~~~~~~~~~~~~~~~~~~

webpack 5.92.0 compiled with 1 error and 2 warnings in 29953 ms

last working version was @carbon/charts@1.16.6

@uniquejava
Copy link

Same issue here with Angular 18 and @carbon/charts-angular": "^1.19.2, I have to manually install the following dev dependencies:

  "devDependencies": {
    ...
    "@types/d3": "^7.4.3",
    "@types/topojson-specification": "^1.0.5",
}

@nstuyvesant
Copy link
Contributor

@huineng and @uniquejava - do your tsconfig.json files have

{
  "compilerOptions": {
    "skipLibCheck": true
  }
}

Wondering if your projects are unnecessarily checking types in your dependency on @carbon/charts or @carbon/charts-angular. The core package has its own devDependencies that include @types/topojson (which includes @types/topojson-specification) and @types/d3.

Your projects generally shouldn't need these type declarations unless you are directly using those types.

@huineng
Copy link
Author

huineng commented Aug 13, 2024

i have skipLibCheck set to false. And i have installed topojson-specification to avoid compilation issues.

My opinion is that dev dependencies are used during development. So you develop , build and publish and the dependencies should no longer be needed. But you publish the package with the dependency, and so for us doing further development on carbon charts, we do need to have that package installed.

As npm does not install dev dependencies from 3th parties, we have to do it ourselves.

So whatever code you publish that contains a dependency on another package, should include that package as a dependency.

Thanks

@uniquejava
Copy link

Thanks for your help. "skipLibCheck": true fixed the issues.

No, I don't use these types in my hello world project.

When run npm start for the first time, I see the error originated from this file.

node_modules/@carbon/charts/dist/components/axes/axis.d.ts:

Relevant logs:



Error: node_modules/@carbon/charts/dist/components/axes/axis.d.ts:1:53 - error TS7016: Could not find a declaration file for module 'd3'. '/Users/cyper/github/CarbonPoc/node_modules/d3/src/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/d3` if it exists or add a new declaration (.d.ts) file containing `declare module 'd3';`

1 import { AxisScale, Selection as D3Selection } from 'd3';
                                                      ~~~~


Error: node_modules/@carbon/charts/dist/components/axes/axis.d.ts:20:47 - error TS7016: Could not find a declaration file for module 'd3-selection'. '/Users/cyper/github/CarbonPoc/node_modules/d3-selection/src/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/d3-selection` if it exists or add a new declaration (.d.ts) file containing `declare module 'd3-selection';`

20     getInvisibleAxisRef(): D3Selection<import('d3-selection').BaseType, any, Element, any>;
                                                 ~~~~~~~~~~~~~~


@nstuyvesant
Copy link
Contributor

Hi @huineng - since we publish the .d.ts files that reference some of those types, it's fair to say they should be dependencies. I have an open PR that I added them to.

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

Successfully merging a pull request may close this issue.

3 participants