codesandbox / codesandbox-client

An online IDE for rapid web development
https://codesandbox.io
Other
13.1k stars 2.29k forks source link

Types not working : Cannot find module '@hadihallak/core' or its corresponding type declarations #4828

Closed hadihallak closed 4 years ago

hadihallak commented 4 years ago

🐛 bug report

On codesandbox I get this error Cannot find module '@hadihallak/core' or its corresponding type declarations where if I use this package in a project locally it works both in vscode and during bundling with no issues.

Description of the problem

  1. create a react-typescript codesandbox
  2. import @hadihallak/core (version can be anything from 0.0.3 all the way to 0.0.9)

codesandbox will not be able to resolve the types and it will give this error Cannot find module '@hadihallak/core' or its corresponding type declarations

I tried moving adding a types field to the package.json or just naming the type files differently with no dice.

After a lot of going back and forth, deploying multiple versions of the library, I opened the network tab as I was curious to know if types were being fetched at all and found these two requests related to this package which were giving response errors: https://prod-packager-packages.codesandbox.io/v1/typings/@hadihallak/core/0.0.3.json https://ata.codesandbox.io/api/v8/%40hadihallak%2Fcore%400.0.3.json

It's worth noting that we've recently updated how the library works to move bundling from tsc to preconstruct which uses rollup internally and generates types under a declarations/src/...typesGoHere folder inside the dist folder inside the dist folder it will have a type file that exports everything from the declaration folder like so

export * from "./declarations/src/index";

and the typing issue with codesandbox started only after we did that.

Folder structure for types:

Screen Shot 2020-09-04 at 12 50 21 PM

Related fields from package.json:

  "main": "dist/core.cjs.js",
  "module": "dist/core.esm.js",

Hopefully, this will help.

How has this issue affected you? What are you trying to accomplish?

Can't get the types to work in codesandbox

Link to sandbox: [link]() (optional)

Your Environment

Software Name/Version
Сodesandbox
Browser chrome
Operating System mac os
CompuIves commented 4 years ago

Hey @hadihallak, good find! I've fixed the issue and everything should now work as expected.