3

I have this very simple component in a brand new Sveltekit project:

<script context="module" lang="ts">
    import type { Load } from '@sveltejs/kit';
    export const load: Load = ({ url }) => {
    const company = url.searchParams.get('company');
    return {
      props: {
        company
      }
    };
  }
   
  </script>
<script type="ts">
        export let company: string;

</script>

<h1>{company}</h1>

However, I always get an error at the import line: parse error

This also happens when I run the app outside VSCode, so it's not just a problem with the IDE.

My package.json:

{
    "name": "testapp",
    "version": "0.0.1",
    "scripts": {
        "dev": "svelte-kit dev",
        "build": "svelte-kit build",
        "package": "svelte-kit package",
        "preview": "svelte-kit preview",
        "prepare": "svelte-kit sync",
        "check": "svelte-check --tsconfig ./tsconfig.json",
        "check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
        "lint": "prettier --check --plugin-search-dir=. . && eslint .",
        "format": "prettier --write --plugin-search-dir=. ."
    },
    "devDependencies": {
        "@sveltejs/adapter-static": "^1.0.0-next.34",
        "@sveltejs/kit": "next",
        "@typescript-eslint/eslint-plugin": "^5.27.0",
        "@typescript-eslint/parser": "^5.27.0",
        "eslint": "^8.16.0",
        "eslint-config-prettier": "^8.3.0",
        "eslint-plugin-svelte3": "^4.0.0",
        "prettier": "^2.6.2",
        "prettier-plugin-svelte": "^2.7.0",
        "svelte": "^3.44.0",
        "svelte-check": "^2.7.1",
        "svelte-preprocess": "^4.10.6",
        "tslib": "^2.3.1",
        "typescript": "^4.7.2"
    },
    "type": "module"
}

Does anybody have an idea what's going wrong here?

1 Answer 1

7

Found the solution: when changing the adpater, I accidently removed svelte preprocess from svelte.config.js. Doing it like this, and it works perfcetly fine:

import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    // Consult https://github.com/sveltejs/svelte-preprocess
    // for more information about preprocessors
    preprocess: preprocess(),

    kit: {
        adapter: adapter()
    }
};

export default config;
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for this! I did the same thing because of the sveltekit documentation on the static adapter: kit.svelte.dev/docs/adapter-static#usage
Ah thanks for the hint, I wasn't aware that it was missing in the documentation. I created a PR to change that: github.com/sveltejs/kit/pull/8811
While the PR was denied so the docs stay the same (for good reasons - if you use vanilla JS you don't need that for example) we might get a better error message in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.