vite-pwa / sveltekit

Zero-config PWA Plugin for SvelteKit
https://vite-pwa-org.netlify.app/frameworks/sveltekit
MIT License
324 stars 15 forks source link

Error during build: Cannot find package 'kolorist' #39

Open udos86 opened 1 year ago

udos86 commented 1 year ago

Building a SvelteKit application with latest @vite-pwa/sveltekit fails out of the box with the following error:

error during build:
Error [PLUGIN_ERROR]: Cannot find package 'kolorist' imported from C:\xx\xx\sveltekit-sample\node_modules\@vite-pwa\sveltekit\dist\chunks\log.mjs
    at new NodeError (node:internal/errors:399:5)
    at packageResolve (node:internal/modules/esm/resolve:889:9)
    at moduleResolve (node:internal/modules/esm/resolve:938:20)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)

My package versions:

"@sveltejs/kit": "1.15.0"
"@vite-pwa/sveltekit": "2.0.1"
"vite-pwa-plugin": "0.14.7"

After installing kolorist manually everything works fine.

So in order to fix this, kolorist should be added to dependencies and removed from devDependencies in package.json of @vite-pwa/sveltekit.

My service worker under src/service-worker.ts:

import { precacheAndRoute } from 'workbox-precaching';

declare const self: ServiceWorkerGlobalScope;

precacheAndRoute(self.__WB_MANIFEST);

My Vite config:

import { sveltekit } from '@sveltejs/kit/vite';
import { SvelteKitPWA } from '@vite-pwa/sveltekit';

/** @type {import('vite').UserConfig} */
const config = {
    plugins: [
        sveltekit(),
        SvelteKitPWA({
            strategies: 'injectManifest'
        })
    ],
    test: {
        include: ['src/**/*.{test,spec}.{js,ts}']
    },
    // see https://vite-pwa-org.netlify.app/frameworks/sveltekit.html#generate-custom-service-worker
    define: {
        'process.env.NODE_ENV': process.env.NODE_ENV === 'production'
            ? '"production"'
            : '"development"'
    }
};

export default config;
userquin commented 1 year ago

@udos86 thx, I need to review all dependencies

haleksandre commented 1 year ago

I think this happens because kolorist is in your devDependencies & is listed as an external but you import it here https://github.com/vite-pwa/sveltekit/blob/c6c34992a1cd5cec2bb58ea1ae82273c9308048c/src/plugins/SvelteKitPlugin.ts#L106 to log info to the console during vite build process.

You should probably remove kolorist from the external here?

https://github.com/vite-pwa/sveltekit/blob/c6c34992a1cd5cec2bb58ea1ae82273c9308048c/build.config.ts#L11

m1rm commented 1 year ago

might be nice to know: I ran into this issue and setting babel: false, in the svelte.config.js fixed my failing prod build and the build results were as expected afterwards

madfrag commented 1 year ago

any news on this one? :)

rikimbili commented 1 year ago

Any updates on this issue? We also encountered it.