Skip to content

Remove the need for an index file with npm run package #2884

Open
@Rich-Harris

Description

@Rich-Harris

Describe the problem

Following #2431, npm run package prints the following if you don't have an index.svelte, index.js or index.ts:

Cannot generate a "svelte" entry point because the "." entry in "exports" is missing. Please specify one or set a "svelte" entry point yourself

It's not very clear what this means.

Describe the proposed solution

My first instinct is to just try and make the language clearer, but really the issue here is that the "svelte" field is bad and we should get rid of it. Back in the day, it was added so that a package could export a compiled module alongside the uncompiled component: if your app was using Svelte (i.e. you were using a bundler plugin that knew how to interpret "svelte") you would get the component, but otherwise you would import the JS module.

This felt like a good idea at the time but it's really not. It's unwanted magic (if you want to expose both, do so, but explicitly), and it only works with a main entry point, at a time when there's a standardised way to express subpaths within packages.

Unfortunately, it persists, at least partly because we opted to use it as a signal that a given package should be forcibly included in noExternal so that it gets processed by Vite.

Possible solutions:

  • add "svelte": true instead of a path
  • if that's too breaky (since it's used for resolution by e.g. rollup-plugin-svelte), add a new field and update the Vite plugin to account for it. Something like "sveltekit": { "noExternal": true } or something. Then again that is weirdly Kit-specific
  • update rollup-plugin-svelte etc so that we can just use a boolean
  • emit an index.js that just throws an error when you import it, and point "svelte" at that
  • work with the Vite team to come up with a new field that tells Vite to exclude a given package. This is probably the best approach since it's not Svelte-specific, and is directly related to the problem it solves, but would require external buy-in

Alternatives considered

No response

Importance

would make my life easier

Additional Information

This whole thing is my fault, sorry

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions