You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to import the "@heroiclabs/nakama-js" library into a SvelteKit project, but building always fails as it thinks the library is a CommonJS module. The "package.json" file in the library has a CommonJS file specified in "main", but also a ES6 module specified in "module", which seems to be ignored. I can't seem to reproduce the issue with Firebase for example, which has a similar structure, but doing the same steps from a vite project seems to work fine, so I don't think it's a bug in the library itself. A workaround I've found is to manually edit the "package.json" file of the library and changing the "main" to use the module file, instead of the CommonJS file.
Install "@heroiclabs/nakama-js" (or possibly any other library).
Initialize the library.
Running "svelte-kit build".
Logs
❯ yarn run build
$ svelte-kit build
vite v2.7.10 building for production...
✓ 15 modules transformed.
.svelte-kit/output/client/_app/manifest.json 1.21 KiB
.svelte-kit/output/client/_app/start-311010a3.js 19.58 KiB / gzip: 6.78 KiB
.svelte-kit/output/client/_app/layout.svelte-8f8cfb61.js 0.53 KiB / gzip: 0.35 KiB
.svelte-kit/output/client/_app/error.svelte-20cdcf24.js 1.56 KiB / gzip: 0.75 KiB
.svelte-kit/output/client/_app/pages/index.svelte-cf1af39f.js 0.83 KiB / gzip: 0.48 KiB
.svelte-kit/output/client/_app/chunks/vendor-2e3f37b6.js 15.73 KiB / gzip: 5.85 KiB
.svelte-kit/output/client/_app/assets/start-61d1577b.css 0.16 KiB / gzip: 0.15 KiB
vite v2.7.10 building SSR bundle for production...
✓ 12 modules transformed.
.svelte-kit/output/server/manifest.json 0.92 KiB
.svelte-kit/output/server/app.js 46.82 KiB
.svelte-kit/output/server/entries/pages/layout.svelte.js 0.24 KiB
.svelte-kit/output/server/entries/pages/error.svelte.js 0.72 KiB
.svelte-kit/output/server/entries/pages/index.svelte.js 0.38 KiB
.svelte-kit/output/server/chunks/index-2dc61825.js 2.24 KiB
Run npm run preview to preview your production build locally.
> Using @sveltejs/adapter-static
file:///home/projects/sveltekit-tqnuuh/.svelte-kit/output/server/entries/pages/index.svelte.js:2
import { Client } from "@heroiclabs/nakama-js";
^^^^^^
SyntaxError: Named export'Client' not found. The requested module '@heroiclabs/nakama-js' 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 '@heroiclabs/nakama-js';
const { Client } = pkg;
at async respond$1 (file:///home/projects/sveltekit-tqnuuh/.svelte-kit/output/server/app.js:952:13)
at async render_page (file:///home/projects/sveltekit-tqnuuh/.svelte-kit/output/server/app.js:1111:20)
at async resolve (file:///home/projects/sveltekit-tqnuuh/.svelte-kit/output/server/app.js:1311:104)
at async respond (file:///home/projects/sveltekit-tqnuuh/.svelte-kit/output/server/app.js:1292:12)
> 500 /
at eval (file:///home/projects/sveltekit-tqnuuh/node_modules/@sveltejs/kit/dist/chunks/index5.js:178:11)
at visit (file:///home/projects/sveltekit-tqnuuh/node_modules/@sveltejs/kit/dist/chunks/index5.js:337:5)
Describe the bug
I'm trying to import the "@heroiclabs/nakama-js" library into a SvelteKit project, but building always fails as it thinks the library is a CommonJS module. The "package.json" file in the library has a CommonJS file specified in "main", but also a ES6 module specified in "module", which seems to be ignored. I can't seem to reproduce the issue with Firebase for example, which has a similar structure, but doing the same steps from a vite project seems to work fine, so I don't think it's a bug in the library itself. A workaround I've found is to manually edit the "package.json" file of the library and changing the "main" to use the module file, instead of the CommonJS file.
Reproduction
StackBlitz
Steps:
Logs
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: