kaboom: 'default' is not exported by kaboom.js
I tried to use kaboom in a typescript project setup with vite; however it seems that the default import from kaboom is an empty object:
The error thrown on production build:
~/Documents/dev/games/flappy-like main
❯ yarn build
yarn run v1.22.10
warning package.json: No license field
$ tsc && vite build
vite v2.3.7 building for production...
transforming (2) src/main.tsError when using sourcemap for reporting an error: Can't resolve original location of error.
✓ 3 modules transformed.
'default' is not exported by node_modules/kaboom/dist/kaboom.js, imported by src/main.ts
file: /Users/renan/Documents/dev/games/flappy-like/src/main.ts:1:7
1: import kaboom from "kaboom";
^
2: const k = kaboom();
3: k.scene("start", () => {
error during build:
Error: 'default' is not exported by node_modules/kaboom/dist/kaboom.js, imported by src/main.ts
at error (/Users/renan/Documents/dev/games/flappy-like/node_modules/rollup/dist/shared/rollup.js:7917:30)
at Module.error (/Users/renan/Documents/dev/games/flappy-like/node_modules/rollup/dist/shared/rollup.js:9859:16)
Browser error on dev:

I don’t know if I’m missing something in the vite config or typescript config:
The main.ts file:
import kaboom from 'kaboom'
const k = kaboom() // ⚠️ Throw an error "Uncaught TypeError: kaboom is not a function"
k.scene('start', () => {
// add a text at position (100, 100)
k.add([
k.text("ohhimark", 32),
k.pos(100, 100),
]);
})
k.start('start')
tsconfig.json file
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["esnext", "DOM"],
"moduleResolution": "node",
"strict": true,
"sourceMap": true,
"resolveJsonModule": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"esModuleInterop": true,
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noImplicitAny": false,
"isolatedModules": true,
"typeRoots": [
"node_modules/**/*.d.ts"
],
},
"include": ["./src/*.ts"]
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 17 (8 by maintainers)
Oh
start()is removed in favor ofgo(), is that the problem?Nice! I believe the package / bundler issue is resolve, closing.
Oh, it seems that start() was the Problem. So
import kaboom from "kaboom";works fine 😃I tested it and it works too @slmjkdbtl ! adding
.mjsand.cjsversions fixes the issue 👍In my case I was able to bypass this issue (for vitejs) by adding an alias pointing to the kaboom package:
But I confirm that adding the
moduleandmainfields is working fineAdding the
moduleandmainfield to point to the.mjsand.cjs(8055546) seems to fix thisCan anyone verify by cloning and installing the library locally? (it’s possible your code might break due to other hanging breaking changes on master which is unrelated to this)
With parcel: import kaboom from “…/node_modules/kaboom/dist/kaboom.mjs”;
Looks like vite (is it using rollup?) is ignoring the
exportsfield in kaboom’spackage.jsonand always using thekaboom.jswhich exposes towindowinstead of moduleI only tested package with
esbuildand it works. I’ll investigate into this, but if anyone is familiar with distributing packages for allcjs,umdandiifehelp is appreciated!Hello.
I have solved the problem using full path to kaboom packages. Using vite and vanilla javascript, not typescript.
import kaboom from '../node_modules/kaboom/dist/kaboom';With typescript must use .d.td module.
I’m having the same issue. Tried with just javascript and typescript, using parcel the error I get is: