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.

Imports don't work in typescript

See original GitHub issue

I’d like to directly import required types, and not utilize the types field in tsconfig.json.

During development it all seems to work fine, but whenever I run wrangler dev I get errors like this: No matching export in "node_modules/@cloudflare/workers-types/2022-08-04/index.ts" for import "Response".

What’s the correct way to import?

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
penalosacommented, Dec 1, 2022

I think this might be a case of us not being clear enough in documentation—we can definitely try and improve that!

To clarify, you’re able to import types directly if your use case will fit within the constraints of import type {...}, which essentially require that they can be fully stripped out at build time, and have no runtime component. When you do import { Response } from "@cloudflare/workers-types/experimental", and use it as new Response(), typescript is unable to strip out the Response import at build time, as it’s used at runtime. For that use case, using tsconfig.json is the recommended way forward.

We intend for the importable types to be used in cases where you have to also use libdom, and situations like that. If you’re just writing a worker, using tsconfig.json will most closely reflect the actual runtime types available to your code.

0reactions
GingerAdoniscommented, Dec 1, 2022

I’d say the documentation is somewhat vague about it, as it mentions “which are usable with no additional tsconfig.json setup”. Which I interpreted as importing without referencing the types in tsconfig.json. I assumed that workerd strips or ignores the related imports.

Ideally it should be possible to explicitly import without messing with tsconfig.json.

This issue can be closed if you see this is a non-issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import statement does not work in typescript - Stack Overflow
Then I'm trying to import a class in a file using 'import' keyword. But despite having read about the declaration of modules in...
Read more >
Imports not working in TypeScript project. · Issue #199 - GitHub
When I am trying to import any of the Props into a TypeScript project, import sizes from "open-props/src/sizes" I get a ts(2307) Error:...
Read more >
Common TypeScript module problems and how to solve them
Resolving modules in multiple locations can be a bit challenging because at this point in your code, the compiler does not know how...
Read more >
Documentation - Modules - TypeScript
Often modules extend other modules, and partially expose some of their features. A re-export does not import it locally, or introduce a local...
Read more >
3 Different Ways to Import Modules in TypeScript | by Wei Kang
If we were to use this method to import modules without installing the @types/node package, we will have a complaint from TypeScript as...
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