【问题标题】:"rollup-plugin-svelte" The following packages did not export their `package.json`“rollup-plugin-svelte”以下包没有导出它们的`package.json`
【发布时间】:2021-12-14 12:45:25
【问题描述】:

我是 svelte.js 的新手。请帮我解决它

在这里,当我在 .svelte 文件中导入 swiper carousel 时。它告诉我这个错误是

[rollup-plugin-svelte] 以下软件包未导出其package.json 文件,因此我们无法检查“svelte”字段。如果您在从包中导入 svelte 组件时遇到困难,请联系作者并要求他们导出 package.json 文件。

Screenshot of Terminal Error. Please check this

这是我的代码文件。这是轮播滑块的另一个组件。但是我在导入 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>

【问题讨论】:

    标签: javascript import svelte swiper rollup


    【解决方案1】:

    TL;DR

    如果该错误来自不导出 svelte 组件的模块(例如,streamutilis-odd;导出 Javascript 文件的模块),则可以安全地忽略此错误。你甚至可以通过在rollup.config.js 中覆盖onwarn 来隐藏它:

    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()`
        ],
    }
    

    小解释

    之所以发出它,是因为某些模块使用 exports 字段在 package.json 中指定了它们要导出的文件,但它们并未在该字段中包含 package.json 本身。这与rollup-plugin-svelte 识别导出svelte 组件的模块的方式相混淆——通过读取package.json(它不能导入特别未导出的内容!)。 Here 在插件的 Github 页面上提供了更多技术解释,关于插件为什么会这样做以及它的好处。

    【讨论】:

    • 感谢您的帮助。但仍然显示此错误...
    【解决方案2】:

    目前没有办法消除此警告。然而,在 GitHub 存储库上有一个关于它的未解决问题。

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

    【讨论】:

      猜你喜欢
      • 2020-05-10
      • 1970-01-01
      • 2021-03-14
      • 2019-01-19
      • 2020-12-27
      • 2021-12-14
      • 2020-10-20
      • 2021-10-25
      • 1970-01-01
      相关资源
      最近更新 更多