Issue
I'm creating a virtual scroller Vue 3 NPM library.
Full source code
Problem
It seems I'm not exporting or generating TS types properly. I specified the type paths in configs, package.json, etc, but it's still not generating any TS types.
When I import the library in another project as follows:
import {VirtualScroller, VirtualScrollerRow} from 'sigma-scrollkit';
import type {VirtualEntry} from 'sigma-scrollkit';
I get this error:
Cannot find module 'sigma-scrollkit' or its corresponding type declarations
Library code
Package.json
"files": [
"dist",
"types/index.d.ts"
],
"type": "module",
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
tsconfig.json
{
"compilerOptions": {
"outDir": "dist/types",
"baseUrl": "./",
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"moduleResolution": "node",
"isolatedModules": true,
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom", "dom.iterable", "scripthost"],
"skipLibCheck": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}
vite config
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
name: 'sigma-scrollkit',
fileName: 'sigma-scrollkit'
},
outDir: 'dist',
emptyOutDir: true,
minify: true,
rollupOptions: {
external: ['vue'],
output: {
// Global vars for UMD build
globals: {
vue: 'Vue'
}
}
}
},
...
})
Solution
Try to add a index.d.ts at project root, like this.
Or point to types folder not from dist folder, like this.
Answered By - Sombriks
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.