Support external svelte module with component main entry (svelte key in package.json)
See original GitHub issue{
"name": "@sveltech/routify",
"version": "0.0.0-development",
"description": "Routes for Svelte, automated by your filestructure",
"main": "lib/index.js",
"svelte": "runtime/index.js",
The svelte key is what is being resolved within Svelte apps, but code completion doesn’t work, since VSCode uses the main key.
Could not find a declaration file for module '@sveltech/routify'. '... routify/lib/index.js' implicitly has an 'any' type.
_Originally posted by @jakobrosenberg in https://github.com/sveltejs/language-tools/pull/9#issuecomment-612420470_
As @jakobrosenberg point out. The svelte key in external module’s package.json
is a special custom main entry for svelte component source. See rollup-plugin-svelte for more info. This custom entry should be consider when resolving svelte module
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Docs • Svelte
Components are the building blocks of Svelte applications. They are written into .svelte files, using a superset of HTML. All three sections —...
Read more >Packaging • Docs • SvelteKit
Running the svelte-package command from @sveltejs/package will take the contents of src/lib and generate a package directory (which can be configured) ...
Read more >Introduction • Docs • SvelteKit
It uses Vite with a Svelte plugin to provide a lightning-fast and feature-rich development experience with Hot Module Replacement (HMR), where changes to...
Read more >Configuration • Docs • SvelteKit
Your project's configuration lives in a svelte.config.js file at the root of your project. As well as SvelteKit, this config object is used...
Read more >Lifecycle / onMount • Svelte Tutorial
Every component has a lifecycle that starts when it is created, and ends when it is destroyed. There are a handful of functions...
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 Free
Top 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
Upon further study on how to implement, I actually not so sure if this is needed to be implement. As this custom main field is used by bundler/ builder like webpack and rollup. But for the language-server, reading from source means it would have to recompile it every time, which is more inefficient. Also, as the doc of rollup-plugin-svelte said:
It seems to means the field isn’t intended to be required to build. It’s like the more commonly used ‘source’ field but a svelte version. And typescript’s module-resolving doesn’t support custom entry too.
Maybe it could still be implemented but under some configuration with glob array to test for.
I assume you talk about providing types as a library author.
There is nothing official yet. For now the best way is to copy the contents of this class into your types and make all components extend that like