"rollup-plugin-svelte" The following packages did not export their `package.json`
Asked Answered
F

2

5

I am new in svelte.js. help me please to fix it

Here, when I import the swiper carousel at my .svelte file. it shows me this error which is

[rollup-plugin-svelte] The following packages did not export their package.json file so we could not check the "svelte" field. If you had difficulties importing svelte components from a package, then please contact the author and ask them to export the package.json file.

Screenshot of Terminal Error. Please check this

This is my code file. here is another component of a carousel slider. but I am seeing this picture when I import the swiper carousel.

<script>
    import { Swiper, SwiperSlide } from "swiper/svelte";
    import PorfolioCard from "./../components/porfolio-card.svelte";
    import SectionTitle from "./../components/sectionTitle.svelte";
    import "swiper/css";
</script>

<section id="portfolio">
    <SectionTitle title="My Portfolio" subtitle="Visit My Portfolio And Keep your feedback" />

    <div class="mt-4 px-1 px-md-3 px-lg-5">
        <Swiper>
            <SwiperSlide>
                <PorfolioCard />
            </SwiperSlide>

            <SwiperSlide>
                <PorfolioCard />
            </SwiperSlide>

            <SwiperSlide>
                <PorfolioCard />
            </SwiperSlide>

            <SwiperSlide>
                <PorfolioCard />
            </SwiperSlide>

            <SwiperSlide>
                <PorfolioCard />
            </SwiperSlide>
            
        </Swiper>
    </div>
</section>
Fornax answered 29/10, 2021 at 12:31 Comment(0)
P
5

There is not currently a way to silence this warning. There is however an open issue on the GitHub repo regarding it.

https://github.com/sveltejs/rollup-plugin-svelte/issues/181

Update:

Evidently this has since been addressed here and the open issue mentioned previously has be closed as a result.

Postbellum answered 1/11, 2021 at 21:14 Comment(0)
F
2

TL;DR

This error can be safely ignored if it's coming from modules that don't export svelte components (eg. stream, util, is-odd; modules that export Javascript files). You can even hide it via overriding onwarn in rollup.config.js:

const onwarn = (message, warn) => {
    const ignored = {
        PLUGIN_WARNING: ['`package.json`'],
    };
    const ignoredKeys = Object.keys(ignored);
    const ignoredValues = Object.values(ignored);

    for (let i = 0, l = ignoredKeys.length; i < l; ++i) {
        const ignoredKey = ignoredKeys[i];
        const ignoredValue = ignoredValues[i];

        for (const ignoredValuePart of ignoredValue) {
            if (message.code !== ignoredKey
                || !message.toString().includes(ignoredValuePart)) {
                continue;
            }

            return;
        }
    }

    warn(message);
};

export default {
    output: {
        format: 'esm',
        name: 'app',
        dir: 'public',
    },
    onwarn,
    plugins: [
        // your plugins, eg. `svelte()`
    ],
}

Mini-explanation

It's emitted because some modules specify the files they're exporting in package.json using the exports field, but they don't include package.json itself in the field. This messes with how rollup-plugin-svelte identifies modules which export svelte components — by reading package.json (it can't import what's specifically not exported!). Here's some more technical explanation on the plugin's Github page, regarding why the plugin does things like that & the benefits of it.

Firedamp answered 31/10, 2021 at 7:51 Comment(1)
thanks for your help. but still showing this error...Fornax

© 2022 - 2024 — McMap. All rights reserved.