TypeScript Declarations not found when using export maps
See original GitHub issueDescribe 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
:
To Reproduce
- Clone https://github.com/TheComputerM/langserver-ts-bug
- Using PNPM run
pnpm i
- RUN
cd app
- Open in VSCode
- Open
src/Page.svelte
- See Error
Expected behavior No ts error
Information about your project:
- Windows 10
svelte-preprocess
version 4.7.3
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed on master already, release soon
Fixed with the latest release. Note that you need to set
"moduleResolution": "node16"
(or “nodenext”) in yourtsconfig
in order for the export map to get noticed - this has some other implications on relative import paths though, more about that in #1522