sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.71k stars 1.94k forks source link

adapter-static error: config.kit.adapter should be an object with an "adapt" method #645

Closed stordahl closed 3 years ago

stordahl commented 3 years ago

Describe the bug Just spun up a project following the docs. I installed the static adapter and tried to modify svelte.config.cjs to use the static adapter but the server wont spin up. App otherwise runs with the node adapter.

Logs

> sveltekit-first-look@0.0.1 dev
> svelte-kit dev "--open"

config.kit.adapter should be an object with an "adapt" method. See https://kit.svelte.dev/docs#adapters
Error: config.kit.adapter should be an object with an "adapt" method. See https://kit.svelte.dev/docs#adapters
    at Object.validate (file:///Users/stordahl/Code/sveltekit-first-look/node_modules/@sveltejs/kit/dist/cli.js:162:13)
    at validate (file:///Users/stordahl/Code/sveltekit-first-look/node_modules/@sveltejs/kit/dist/cli.js:341:28)
    at validate (file:///Users/stordahl/Code/sveltekit-first-look/node_modules/@sveltejs/kit/dist/cli.js:339:19)
    at validate_config (file:///Users/stordahl/Code/sveltekit-first-look/node_modules/@sveltejs/kit/dist/cli.js:402:20)
    at load_config (file:///Users/stordahl/Code/sveltekit-first-look/node_modules/@sveltejs/kit/dist/cli.js:381:20)
    at async get_config (file:///Users/stordahl/Code/sveltekit-first-look/node_modules/@sveltejs/kit/dist/cli.js:431:10)
    at async file:///Users/stordahl/Code/sveltekit-first-look/node_modules/@sveltejs/kit/dist/cli.js:474:18

To Reproduce I have made sure all pkgs are up to date. Project is in remote here

Expected behavior Just expecting the server to spin up with the static-adapter installed

Stacktraces If you have a stack trace to include, we recommend putting inside a <details> block for the sake of the thread's readability:

Stack trace Stack trace goes here...

Information about your SvelteKit Installation:

System:
    OS: macOS 10.15.7
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    Memory: 56.84 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 15.11.0 - /usr/local/bin/node
    npm: 7.6.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 89.0.4389.90
    Firefox Developer Edition: 87.0
    Safari: 13.1.3
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.58 
    svelte: ^3.29.0 => 3.35.0 

Severity Not severe, just trying to test SvelteKit out in static mode.

benmccann commented 3 years ago

Just to make sure you're using the latest, try changing https://github.com/stordahl/sveltekit-first-look/blob/bddd1dca3676b48f38cb506268603c0be0686589/package.json#L11 to just say next instead of ^1.0.0-next.0. Then delete the package-lock.json and run npm install again

stordahl commented 3 years ago

Try changing https://github.com/stordahl/sveltekit-first-look/blob/bddd1dca3676b48f38cb506268603c0be0686589/package.json#L11 to just say next instead of ^1.0.0-next.0. Then delete the package-lock.json and run npm install again

Got the same error when starting the dev server

benmccann commented 3 years ago

It looks like you changed it to ^1.0.0-next. Can you change it to literally just next like the other @sveltejs packages in package.json?

stordahl commented 3 years ago

Got it, sorry about the confusion! Adapter is working now, thanks for the help @benmccann

benaltair commented 3 years ago

@benmccann I'm getting the same error and unfortunately the above steps don't seem to work for me.

Here's my the branch I'm working on: https://github.com/bahaistudies/conference/tree/sveltekit-migration

What I'm seeing on the console after running npm run dev:

config.kit.adapter should be an object with an "adapt" method. See https://kit.svelte.dev/docs#adapters
Error: config.kit.adapter should be an object with an "adapt" method. See https://kit.svelte.dev/docs#adapters
    at Object.validate (file:///D:/Github/conference/node_modules/@sveltejs/kit/dist/cli.js:162:13)
    at validate (file:///D:/Github/conference/node_modules/@sveltejs/kit/dist/cli.js:341:28)
    at validate (file:///D:/Github/conference/node_modules/@sveltejs/kit/dist/cli.js:339:19)
    at validate_config (file:///D:/Github/conference/node_modules/@sveltejs/kit/dist/cli.js:402:20)
    at load_config (file:///D:/Github/conference/node_modules/@sveltejs/kit/dist/cli.js:381:20)
    at async get_config (file:///D:/Github/conference/node_modules/@sveltejs/kit/dist/cli.js:431:10)
    at async file:///D:/Github/conference/node_modules/@sveltejs/kit/dist/cli.js:474:18
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! conference@0.0.1 dev: `svelte-kit dev`
npm ERR! Exit status 1

I've tried using @sveltejs/adapter-netlify and @sveltejs/adapter-node and get the same errors. I've reset svelte.config.cjs to the initial Svelte-Kit starter file and get the same error.

package.json

{
    "name": "conference",
    "version": "0.0.1",
    "scripts": {
        "dev": "svelte-kit dev",
        "build": "svelte-kit build",
        "start": "svelte-kit start",
        "lint": "prettier --check . && eslint .",
        "format": "prettier --write ."
    },
    "devDependencies": {
        "@sveltejs/adapter-netlify": "next",
        "@sveltejs/adapter-node": "next",
        "@sveltejs/kit": "next",
        "svelte": "^3.29.0",
        "vite": "^2.1.0",
        "typescript": "^4.0.0",
        "tslib": "^2.0.0",
        "svelte-preprocess": "^4.0.0",
        "@typescript-eslint/eslint-plugin": "^4.19.0",
        "@typescript-eslint/parser": "^4.19.0",
        "eslint": "^7.22.0",
        "eslint-plugin-svelte3": "^3.1.0",
        "prettier": "~2.2.1",
        "prettier-plugin-svelte": "^2.2.0",
        "eslint-config-prettier": "^8.1.0"
    },
    "type": "module",
    "engines": {
        "node": ">= 12.17.0"
    },
    "dependencies": {
        "dayjs": "^1.10.4",
        "svelte-icons": "^2.1.0"
    }
}

svelte.config.cjs:

/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const sveltePreprocess = require('svelte-preprocess');
const netlify = require('@sveltejs/adapter-netlify');
const node = require('@sveltejs/adapter-node');
const pkg = require('./package.json');

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

        // hydrate the <div id="svelte"> element in src/app.html
        target: '#svelte',

        vite: {
            ssr: {
                noExternal: Object.keys(pkg.dependencies || {})
            }
        }
    }
};
benaltair commented 3 years ago

Update: I was able to get it to work one step further with adapterNetlify() instead. No idea why the difference to be honest. svelte.config.cjs file below:

/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const sveltePreprocess = require('svelte-preprocess');
const netlify = require('@sveltejs/adapter-netlify');
const node = require('@sveltejs/adapter-node');
const pkg = require('./package.json');
const adapterNetlify = require('@sveltejs/adapter-netlify');

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

        // hydrate the <div id="svelte"> element in src/app.html
        target: '#svelte',

        vite: {
            ssr: {
                noExternal: Object.keys(pkg.dependencies || {})
            }
        }
    }
};

Now the console doesn't complain, but in the browser I get the following error:

SyntaxError: Unexpected token (6:187)
    at Object.pp$4.raise (D:\Github\conference\node_modules\vite\dist\node\chunks\dep-efe32886.js:35243:13)
    at Object.pp.unexpected (D:\Github\conference\node_modules\vite\dist\node\chunks\dep-efe32886.js:32935:8)
    at Object.pp.expect (D:\Github\conference\node_modules\vite\dist\node\chunks\dep-efe32886.js:32929:26)
    at Object.pp$3.parseObj (D:\Github\conference\node_modules\vite\dist\node\chunks\dep-efe32886.js:34879:12)
    at Object.pp$3.parseExprAtom (D:\Github\conference\node_modules\vite\dist\node\chunks\dep-efe32886.js:34618:17)
    at Object.pp$3.parseExprSubscripts (D:\Github\conference\node_modules\vite\dist\node\chunks\dep-efe32886.js:34445:19)
    at Object.pp$3.parseMaybeUnary (D:\Github\conference\node_modules\vite\dist\node\chunks\dep-efe32886.js:34422:17)
    at Object.parseMaybeUnary (D:\Github\conference\node_modules\vite\dist\node\chunks\dep-efe32886.js:42964:29)
    at Object.pp$3.parseExprOps (D:\Github\conference\node_modules\vite\dist\node\chunks\dep-efe32886.js:34357:19)
    at Object.pp$3.parseMaybeConditional (D:\Github\conference\node_modules\vite\dist\node\chunks\dep-efe32886.js:34340:19)

This is the same error I'd gotten when first installing the template. I've tried deleting node_modules and force clearing npm cache but no luck.

Is this related to the same issue? If not, I'm happy to make a new issue.

benaltair commented 3 years ago

After further testing an a few more commits I was able to get netlify build (svelte-kit build) to work, and of course then netlify deploy produces a working site: https://605c3c39f78cc25cb7029840--abs2021.netlify.app/

It seems like the above issue is mainly to do with the dev server, rather than the build process. I'm still get familiar with the open source process so please let me know if you'd rather these notes on a separate issue or anything.

aral commented 3 years ago

If the above steps don’t work for you (i.e., you change ^1.0.0-next to next and npm i and still get the same error with adapter-static), explicitly run:

npm i @sveltejs/adapter-static@next

And that should fix it.