sswr icon indicating copy to clipboard operation
sswr copied to clipboard

SvelteKit - Named export 'SWR' not found

Open mikenikles opened this issue 3 years ago • 1 comments

I use sswr in a SvelteKit application ("@sveltejs/kit": "^1.0.0-next.442").

In dev, everything works fine. However, when I run npm run build and npm run preview and load a page that imports sswr, I see the following error:

SyntaxError: Named export 'SWR' not found. The requested module 'swrev' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'swrev';
const { SWR } = pkg;

Does anyone have a working example of sswr with SvelteKit? Maybe @khromov because of #34 🤔?

mikenikles avatar Aug 27 '22 04:08 mikenikles

Ah yeah, because vite 3 outputs and expects .mjs modules instead of .esm.js. I noticed that too. The fix is update this lib to vite 3 and change the pkg exports. Will do.

ConsoleTVs avatar Aug 27 '22 08:08 ConsoleTVs

Vite CommonJS Plugin might get this working.

arunrdd avatar Feb 27 '23 11:02 arunrdd

Fixed

ConsoleTVs avatar Mar 07 '23 18:03 ConsoleTVs