0

As a beginner to web development, I am building a simple game using Svelte.js with JavaScript and Kaboom.js. However, I am encountering an error("Expected 0 arguments, but got 1.ts(2554) Error") in the main.js file after adding a game component to my app.svelte file. Despite my efforts to search for answers on Google, I have been unable to find a solution to the error. I am seeking assistance to understand what I did wrong and how to resolve the issue.

Main.js

  import './app.css'

  import App from './App.svelte'

  const app = new App({

  target: document.getElementById('app'),

  })

  export default app

App.svelte

<script>
import Game from './lib/game.svelte'
let scroll;
</script>

<svelte:window bind:scrollY={scroll}/>

<main>


<div id="one" class="box" style:transform={'translate3d:(0, 
${scroll*1}px,0)'}></div>
<div id="two" class="box" style:transform={'translate3d:(0, 
${scroll*-1}px,0)'}>

<Game />
</div>

</main>

<style>

#one
{

  height: 100vh;
  width: 100vw;

 }

#two
{

  height: 100vh;
  width: 100vw;
  position: relative;

  </style>

game.svelte

<script>
import kboom from 'kaboom'
</script>

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" 
 />
<title>Vite + Svelte</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

I tried to add game component to my app.svelte file. But after getting error in main.js I tried to find the argument that causes the problem but I couldn't find it. when I searching on internet it says something about typescript but I didn't use typescript in my project.so I'm really confused!

2 Answers2

0

First, your code does nothing, you import and kaboom and do nothing with it, you need to initialize it.

Next, you need for DOM to be ready before initializing kaboom. You do that by importing the onMount helper function.

You can check a minimal working REPL here.

Michael M.
  • 10,486
  • 9
  • 18
  • 34
Tonton-Blax
  • 429
  • 4
  • 6
0

If you are using VSCODE, change the Version of TypeScript, e.g. 4.8.4, and it should work fine.

K T
  • 11
  • 1
  • this error came from a main.js file & my code doesn't contain any typescript files. i do have a typescript plugin enable but is it affecting this error i have? –  Mar 09 '23 at 17:27