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.

TypeScript Declarations not found when using export maps

See original GitHub issue

Describe the bug Suppose I have a npm package named package. The package.json of package looks like:

{
  "name": "package",
  "version": "1.0.0",
  "main": "index.js",
  "types": "./types/index.d.ts",
  "exports": {
    ".": {
      "default": "./index.js"
    },
    "./Component": {
      "default": "./Component.svelte"
    }
  }
}

The types directory in package looks like:

- index.d.ts
- Component.d.ts

The content of Component.d.ts is:

/// <reference types="svelte" />
import { SvelteComponentTyped } from 'svelte';

export interface Props {
  /**
   * @default "svelte"
   */
  prop?: string;
}

export default class Component extends SvelteComponentTyped<Props, {}, {}> {}

Now in my app where I have svelte with typescript with the content of the tsconfig.json as

{
  "extends": "@tsconfig/svelte/tsconfig.json",
  "compilerOptions": {
    "moduleResolution": "node",
    "module": "es2020",
    "lib": ["es2020"],
    "target": "es2019",
    "importsNotUsedAsValues": "error",
    "isolatedModules": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "baseUrl": ".",
    "allowJs": true,
    "checkJs": true
  },
  "include": ["src/**/*"]
}

and my svelte.config.js is:

const sveltePreprocess = require('svelte-preprocess');

module.exports = {
  preprocess: sveltePreprocess(),
};

And in my Svelte file I import package/Component:

image

To Reproduce

Expected behavior No ts error

Information about your project:

  • Windows 10
  • svelte-preprocess version 4.7.3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dummdidummcommented, Jun 24, 2022

Fixed on master already, release soon

0reactions
dummdidummcommented, Jun 27, 2022

Fixed with the latest release. Note that you need to set "moduleResolution": "node16" (or “nodenext”) in your tsconfig in order for the export map to get noticed - this has some other implications on relative import paths though, more about that in #1522

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find a declaration file for module 'module-name ...
Here are two other solutions. When a module is not yours - try to install types from @types : npm install -D @types/module-name....
Read more >
Supports `exports` pointing to a TypeScript file, which keeps ...
Workaround for now is just to say .js instead of .ts in the export map - that's enough to get us to find...
Read more >
Documentation - Module Resolution - TypeScript
If you are having resolution problems with import s and export s in TypeScript, ... Path mapping. Sometimes modules are not directly located...
Read more >
Typescript declaration maps ( declarationMap ) support
The "declarationMap" setting in "tsconfig.json" is set correctly and the "dist" folder contains all the sourcemap-files pointing to the "src" ...
Read more >
Modules: Packages | Node.js v19.3.0 Documentation
Files with a .js extension when the nearest parent package.json file ... named exports, which are available if they can be determined through...
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