SvelteKit fails to Run Dev | [plugin externalize-deps] Missing "./vite" export in "@sveltejs/kit" package
Asked Answered
A

1

8

Following the Sveltekit docs here: https://kit.svelte.dev/docs/creating-a-project

Everything is fine up until the npm run dev command, then this results:

$ npm run dev

> [email protected] dev
> vite dev

X [ERROR] [plugin externalize-deps] Missing "./vite" export in "@sveltejs/kit" package

    node_modules/esbuild/lib/main.js:1352:27:
      1352 │         let result = await callback({
           ╵                            ^

    at bail (file:///D:/Sites/sveltekit/hoa/node_modules/vite/dist/node/chunks/dep-ed9cb113.js:15932:8)
    at resolve$1 (file:///D:/Sites/sveltekit/hoa/node_modules/vite/dist/node/chunks/dep-ed9cb113.js:16009:10)
    at resolveExports (file:///D:/Sites/sveltekit/hoa/node_modules/vite/dist/node/chunks/dep-ed9cb113.js:22961:12)
    at resolveDeepImport (file:///D:/Sites/sveltekit/hoa/node_modules/vite/dist/node/chunks/dep-ed9cb113.js:22979:31)
    at tryNodeResolve (file:///D:/Sites/sveltekit/hoa/node_modules/vite/dist/node/chunks/dep-ed9cb113.js:22668:20)
    at file:///D:/Sites/sveltekit/hoa/node_modules/vite/dist/node/chunks/dep-ed9cb113.js:63027:40
    at requestCallbacks.on-resolve (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:1352:28)
    at handleRequest (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:720:19)
    at handleIncomingPacket (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:742:7)
    at Socket.readFromStdout (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:670:7)

  This error came from the "onResolve" callback registered here:

    node_modules/esbuild/lib/main.js:1276:20:
      1276 │       let promise = setup({
           ╵                     ^

    at setup (file:///D:/Sites/sveltekit/hoa/node_modules/vite/dist/node/chunks/dep-ed9cb113.js:63016:27)
    at handlePlugins (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:1276:21)
    at buildOrServeImpl (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:965:5)
    at Object.buildOrServe (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:773:5)
    at D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:2112:17
    at new Promise (<anonymous>)
    at Object.build (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:2111:14)
    at build (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:1958:51)
    at bundleConfigFile (file:///D:/Sites/sveltekit/hoa/node_modules/vite/dist/node/chunks/dep-ed9cb113.js:62980:26)

  The plugin "externalize-deps" was triggered by this import

    vite.config.js:1:278:
      1 │ ..._original_filename = "D:\\Sites\\sveltekit\\hoa\\vite.config.js";const __vite_injected_original_import_meta_url = "file:///D:/Sites/sveltekit/hoa/vite.config.js";import { sveltekit } from '@sveltejs/kit/vite'; 
        ╵                                                                                                                                                                                                ~~~~~~~~~~~~~~~~~~~~  

failed to load config from D:\Sites\sveltekit\hoa\vite.config.js
error when starting dev server:
Error: Build failed with 1 error:
node_modules/esbuild/lib/main.js:1352:27: ERROR: [plugin: externalize-deps] Missing "./vite" export in "@sveltejs/kit" package
    at failureErrorWithLog (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:1591:15)
    at D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:1047:28
    at runOnEndCallbacks (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:1463:61)
    at buildResponseToResult (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:1045:7)
    at D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:1157:14
    at responseCallbacks.<computed> (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:694:9)
    at handleIncomingPacket (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:749:9)
    at Socket.readFromStdout (D:\Sites\sveltekit\hoa\node_modules\esbuild\lib\main.js:670:7)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)

package.json contents:

{
    "name": "hoa",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "dev": "vite dev",
        "build": "vite build",
        "preview": "vite preview"
    },
    "devDependencies": {
        "@sveltejs/adapter-auto": "next",
        "@sveltejs/kit": "next",
        "svelte": "^3.54.0",
        "vite": "^4.0.0"
    },
    "type": "module"
}

vite.config.js contents

import { sveltekit } from '@sveltejs/kit/vite';

/** @type {import('vite').UserConfig} */
const config = {
    plugins: [sveltekit()]
};

export default config;

svelte.config.js contents:

import adapter from '@sveltejs/adapter-auto';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: adapter()
    }
};

export default config;

System Information: Windows Node Version 16.17.0

There were a few things I attempted to resolve the issue without a successful outcome.

I've already tried some things from older GitHub posts such as: https://github.com/sveltejs/vite-plugin-svelte/issues/59

That seemed to be echoed in several posts but had no positive effect.

I then moved up to node 19.2.0 with no positive outcome per this thread: npm run dev not working with sveltekit/vite project

Any thoughts? Seems odd to be stopped right after installing the packages.

Avestan answered 11/12, 2022 at 5:3 Comment(0)
C
14

Adding "type": "module" to my package.json fixed this issue for me.

Consubstantial answered 30/12, 2022 at 20:21 Comment(4)
This solved the issue for me aswell.Mazy
I believe this issue is being worked on so this answer might (hopefuly) be outdated soon - github.com/laravel/vite-plugin/pull/189Consubstantial
How in gods name did you figure this out? This is the type of error that makes me ready to give up development altogether. Thank god for you bradHardworking
@Hardworking i found it elsewhere haha - truth be told, I don't fully understand why this works and in the end it didn't fix my issue. This is the beauty of StackOverflow ;)Consubstantial

© 2022 - 2024 — McMap. All rights reserved.