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.

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonlyu123commented, Apr 14, 2020

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:

if you’re publishing a component to npm, you should ship the uncompiled source (together with the compiled distributable, for people who aren’t using Svelte elsewhere in their app) and include the “svelte” property in your package.json

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.

0reactions
dummdidummcommented, Aug 30, 2020

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

export class YourComponent extends Svelte2TsxComponent<{...props...}, {...events..}, {...slots...}> {}
Read more comments on GitHub >

github_iconTop 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 >

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