codesandbox / codesandbox-client

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

Cannot find module 'xxx' or its corresponding type declarations. #5502

Open Jannchie opened 3 years ago

Jannchie commented 3 years ago

🐛 bug report

Preflight Checklist

Description of the problem

I'm using typescript, It basically works, but it doesn't load the type declarations.

Cannot find module 'xxx' or its corresponding type declarations.

In the package.json file of the library, the location of the type declarations is defined. In the local environment (with vscode), it can correctly find the type definition, but not in the CodeSandBox.

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

I can use this library on CodeSandBox in a JavaScript environment, but I want to be able to take advantage of TypeScript's type inference capabilities.

To Reproduce

Link to sandbox: link

Your Environment

Software Name/Version
Сodesandbox Latest?
Browser Chrome
Operating System Win 10
07akioni commented 3 years ago

I've met exactly the same issue. Reprod link https://codesandbox.io/s/boring-wescoff-uxd0z?file=/src/App.tsx

image

gadicc commented 3 years ago

Hey @SaraVieira, looking at #5191 and #5452 you wanted a ping on similar issues.

3rd reproduction link at https://codesandbox.io/s/yahoo-finance2-312x2?file=/src/index.ts. The code runs fine (and generates output in the browser window, clearly finding/using the module) but in the code editor it says Cannot find module 'xxx' or its corresponding type declarations and the types don't work.

jmyrland commented 3 years ago

Same issue here, regarding the easy-peasy module: https://codesandbox.io/s/naughty-voice-62zy6?file=/src/App.tsx

fantasticsoul commented 3 years ago

Same issue, link here: https://codesandbox.io/s/cra-template-concent-ts-2x347?file=/src/configs/runConcent.ts it works in local vsc ide, but not work in codesandbox. ( I have change the vsc ts version to 1.4.2, just as the same as codesandbox )


update: it woks now

anuoua commented 3 years ago

Same issue, https://codesandbox.io/s/immer-rdx-codesandbox-bug-vb890, it works in local vscode。

lbogdan commented 3 years ago

I'm trying to reproduce this, below is the list of all sandboxes linked in the issue description and comments:

~So the only one not working currently is the second one. We'll take a better look at this and update the issue.~ Actually it worked after some time, probably because of the big type index file of @ricons/fluent.

So types should work properly, at least in all linked sandboxes. Please check again on your end, and let me know whether this is still an issue for you.

cefn commented 3 years ago

I believe I am also experiencing this issue and it is unsolved in today's version of codesandbox.io

For example if I import the app from https://github.com/cefn/lauf/tree/b72aca2a5ffb649c867cd9d7991d1efad3c04d53/apps/counter it compiles from Typescript and runs fine. It is able to pick up types from the explicit declarations @types/react and @types/react-dom but not for the built-in typings of @lauf/store for v0.2.3.

image

However, the types for the package dependency @lauf/store at v0.2.3 are readable by VSCode as shown...

image

Could it be to do with the structure of the type definitions generated by Typescript?

As you can see below they mirror the library file structure with a re-export. Perhaps VSCode can handle this structure but CodeSandbox can't interpret it?

image

cefn commented 3 years ago

I can't explain what's changed but this error has gone away since I originally posted it. The counter application now correctly resolves typings for the @lauf/store and @lauf/store-react modules at 0.2.3. They were recently-published versions at the time, so I don't know if some worker needed to catch up a backlog of npm publishing.

image

sbinlondon commented 3 years ago

@cefn That's good to hear!

@Jannchie @jmyrland @fantasticsoul @anuoua @07akioni your sandboxes seem to be working now too 🎉 I think like @lbogdan it takes a long time to parse and find the modules in some sandboxes? 🤔

I'm interested in why @gadicc is still having the problem, seems to do with relative paths. @DeMoorJasper is this something you can look at or should I tag someone else?

gadicc commented 3 years ago

@sbinlondon, thanks so much for checking in. This was actually working previously, I should have reported back earlier. Not sure when it broke again. And actually the error was different now. We recently switched over to an ESM module, maybe it had something to do with that. Anyways, I just updated to the latest version of our package and everything is working again now flawlessly. So thanks so much and have a great weekend! (cc: @DeMoorJasper - nothing for you to do ;))

DeMoorJasper commented 3 years ago

We've refactored the resolution logic quite a lot since this issue has been reported, so I'll assume this is fixed as it's no longer reproducible. Gonna close this for now, feel free to open this again (or open a new issue) if it happens again

jamime commented 3 years ago

👋 @DeMoorJasper looks like there has been a regression. The examples above are failing again.

Here is an additional example: https://codesandbox.io/s/carbon-react-typescript-template-kq7zh

DeMoorJasper commented 3 years ago

Hey @jamime I can reproduce this, unfortunately I'm not really familiar with this part of the codebase, forwarded this to someone who is. We will update this issue if there's any progress on this.

Sorry for the late reply, must've gotten lost in my Github notifications.

anatoliygatt commented 2 years ago

I face the same issue with a newly published package. https://codesandbox.io/s/demo-for-anatoliygatt-heart-switch-cds5p, it works fine locally in both VSCode and WebStorm.

shenghan97 commented 2 years ago

Just found this package suffering from the same issue as well @react-three/drei, and it's only versions 9.3.6-9.4.3 are affected.

https://prod-packager-packages.codesandbox.io/v1/typings/@react-three/drei/9.4.3.json

comp615 commented 2 years ago

Also seeing this in our private repo. Works in VSCode, compiles and runs fine, but editor gives red lines everywhere. Potentially due to npm workspace usage? Not sure what else it could be

shenghan97 commented 2 years ago

For my case it's actually the ad blocker that's causing the issue. After I disable uBlock everything works fine.

Not sure if other people here uses ad blocker or not.

Just found this package suffering from the same issue as well @react-three/drei, and it's only versions 9.3.6-9.4.3 are affected.

https://prod-packager-packages.codesandbox.io/v1/typings/@react-three/drei/9.4.3.json

lizyChy0329 commented 4 months ago

I think the team developer of codesendbox did not even use what they created.

Official Vue-ts tempalte

demo

image

filipelima18 commented 4 months ago

Hi @lizy0329-biubiubiu. Can you share some additional details about this issue? I just created a new Devbox from our official Vue Devbox template and I can't reproduce the issue you shared.