Missing lifecycle specifier in svelte package. SvelteKit
Asked Answered
S

1

5

I am currently using svelte's context api to pass user data through out my application. Suddenly I came across this error that has practically no documentation anywhere that I could find. The error message is as follows. Missing "./types/runtime/internal/lifecycle" specifier in "svelte" package. By the looks of the complete console output which I will also post, it is coming from this file here:

<script lang="ts">
    import { getContext } from 'svelte';
    import HtmlGenerator from './generate_html';
    import type { Field } from './generate_html';
    import { setContext } from 'svelte/types/runtime/internal/lifecycle';
    import { UserContext } from '../../context';

    setContext('UserContext', UserContext);

    const { is_logged_in, user } = getContext('UserContext');
</script>

For simplicity I have omitted unrelated code. I did not start getting this error until I tried to use the context Api. Here is the full console output:

Internal server error: Missing "./types/runtime/internal/lifecycle" specifier in "svelte" package
  Plugin: vite:import-analysis
  File: C:/javascript_projects/svelte_projects/reactable/src/routes/dashboard/form-builder/+page.svelte
      at e (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:16638:25)
      at n (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:16638:627)
      at o (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:16638:1297)
      at resolveExportsOrImports (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:23396:20)
      at resolveDeepImport (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:23415:31)
      at tryNodeResolve (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:23104:20)
      at Context.resolveId (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:22865:28)
      at Object.resolveId (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:42793:46)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async TransformContext.resolve (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:42521:23)
Error: Missing "./types/runtime/internal/lifecycle" specifier in "svelte" package
    at e (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:16638:25)
    at n (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:16638:627)
    at o (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:16638:1297)
    at resolveExportsOrImports (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:23396:20)
    at resolveDeepImport (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:23415:31)
    at tryNodeResolve (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:23104:20)
    at Context.resolveId (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:22865:28)
    at Object.resolveId (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:42793:46)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async TransformContext.resolve (file:///C:/javascript_projects/svelte_projects/reactable/node_modules/vite/dist/node/chunks/dep-24daf00c.js:42521:23)

This code even works in another project and I have checked to see that my configuration files are all good and they all seem fine. Maybe this project is corrupted?

I tried going through config files: All seem to be fine. Tried turning off typescript for the file: Still nothing. Restarted development server: Same issue.

Stuffy answered 25/4, 2023 at 2:35 Comment(0)
H
10

The correct path to import setContext from is 'svelte':

import { setContext } from 'svelte';

The autocomplete in VSCode sometimes auto imports from these internal paths for some reason which is how you may have ended up with that import line.

Harlandharle answered 25/4, 2023 at 2:56 Comment(1)
Dang auto importsZanze

© 2022 - 2024 — McMap. All rights reserved.