Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running svelte-package #9097

Closed
brucejo75 opened this issue Feb 17, 2023 · 2 comments · Fixed by #9109
Closed

Error running svelte-package #9097

brucejo75 opened this issue Feb 17, 2023 · 2 comments · Fixed by #9109
Labels
bug Something isn't working pkg:svelte-package Issues related to svelte-package

Comments

@brucejo75
Copy link

brucejo75 commented Feb 17, 2023

Describe the bug

From: #8922 (comment)

svelte-package throwing a misleading error on misconfigured package.json

The error advises me to add a svelte condition to my exports. I had one. I really needed to add a svelte condition at the top level.

Reproduction

# Create the project and choose `Skeleton project` (which is what many of the online tutorials do)
$ pnpm create svelte error
$ cd error
$ pnpm install
$ pnpm add svelte2tsx @sveltejs/package
$ pnpm add -P svelte
$ mkdir src/lib
$ echo -e "<h1>Error</h1>\n" > lib/src/ErrComponent.svelte

add "exports" key to package.json

"exports": {
    ".": {
      "types": "./dist/ErrComponent.d.ts",
      "svelte": "./dist/ErrComponent.js"
    }
},

Run svelte-package

$ pnpm svelte-package
src/lib -> dist
@sveltejs/package found the following issues while packaging your library:
You are using Svelte files, but did not declare a `svelte` condition in one of your `exports` in your `package.json`. Add a `svelte` condition to your `exports` to ensure that your package is recognized as Svelte package by tooling. See https://kit.svelte.dev/docs/packaging#anatomy-of-a-package-json-exports for more info

Logs

No response

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (1) x64 Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz
    Memory: 201.78 MB / 904.09 MB
    Container: Yes
    Shell: 5.1.16 - /usr/bin/bash
  Binaries:
    Node: 18.14.0 - ~/.local/share/pnpm/node
    npm: 9.3.1 - ~/.local/share/pnpm/npm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.0.0
    @sveltejs/kit: ^1.5.0 => 1.7.1
    @sveltejs/package: ^2.0.1 => 2.0.1
    svelte: ^3.55.1 => 3.55.1
    vite: ^4.0.0 => 4.1.2

Severity

annoyance

Additional Information

  • if you pnpm create svelte & choose library then package.json adds 2 keys that are important:
"svelte": "./dist/index.js",
"types": "./dist/index.d.ts",

The error is misleading, I had a svelte condition in my exports. I really needed a svelte condition at the top level.

@braebo
Copy link
Member

braebo commented Feb 18, 2023

Technically, it makes sense that this:

Add a svelte condition to your exports

Would mean exports.svelte. Though I can also see how this could be further clarified.

@dominikg
Copy link
Member

I don't think we should force people to put svelte in the top level of exports map.

Alternative solution would be to also search subkeys and not print the message when it was found there

@dummdidumm dummdidumm added bug Something isn't working pkg:svelte-package Issues related to svelte-package labels Feb 18, 2023
dummdidumm added a commit that referenced this issue Feb 20, 2023
* fix: dont emit false positive export condition warning

fixes #9097

* Update .changeset/friendly-pandas-sort.md

Co-authored-by: Conduitry <git@chor.date>

---------

Co-authored-by: Rich Harris <richard.a.harris@gmail.com>
Co-authored-by: Conduitry <git@chor.date>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:svelte-package Issues related to svelte-package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants