Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typecheck fails when import type from ./$types #13614

Closed
fel1x-developer opened this issue Mar 20, 2025 · 3 comments
Closed

typecheck fails when import type from ./$types #13614

fel1x-developer opened this issue Mar 20, 2025 · 3 comments

Comments

@fel1x-developer
Copy link

fel1x-developer commented Mar 20, 2025

Describe the bug

// chart.svelte.ts
import type { Action } from 'svelte/action';
import type { Snapshot } from './$types';
import type { ChartData, ChartOptions, ChartTypeRegistry, UpdateMode } from 'chart.js';
// ...
/Users/minsoochoo/WebstormProjects/chartjs/src/lib/utils/chart.svelte.ts:2:31
Error: Cannot find module './$types' or its corresponding type declarations. 
import type { Action } from 'svelte/action';
import type { Snapshot } from './$types';
import type { ChartData, ChartOptions, ChartTypeRegistry, UpdateMode } from 'chart.js';

Reproduction

Fork https://github.com/sveltejs-labs/chart.js, install dependencies, and run

$ npm run check
# or
$ bun run check
# or any package manager

Logs

$ svelte-kit sync && svelte-check --tsconfig ./tsconfig.json

====================================
Loading svelte-check in workspace: /Users/minsoochoo/WebstormProjects/chartjs
Getting Svelte diagnostics...

/Users/minsoochoo/WebstormProjects/chartjs/src/lib/utils/chart.svelte.ts:2:31
Error: Cannot find module './$types' or its corresponding type declarations. 
import type { Action } from 'svelte/action';
import type { Snapshot } from './$types';
import type { ChartData, ChartOptions, ChartTypeRegistry, UpdateMode } from 'chart.js';


====================================
svelte-check found 1 error and 0 warnings in 1 file
error: script "check" exited with code 1

System Info

System:
    OS: macOS 15.3.2
    CPU: (8) arm64 Apple M2
    Memory: 887.72 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - ~/.local/state/fnm_multishells/97104_1742441833740/bin/node
    npm: 10.9.2 - ~/.local/state/fnm_multishells/97104_1742441833740/bin/npm
    bun: 1.2.5 - ~/.bun/bin/bun
  Browsers:
    Chrome: 134.0.6998.89
    Safari: 18.3.1
  npmPackages:
    @sveltejs/adapter-vercel: ^5.6.3 => 5.6.3 
    @sveltejs/kit: ^2.20.1 => 2.20.1 
    @sveltejs/package: ^2.3.10 => 2.3.10 
    @sveltejs/vite-plugin-svelte: ^5.0.3 => 5.0.3 
    svelte: ^5.23.2 => 5.23.2 
    vite: ^6.2.2 => 6.2.2

Severity

annoyance

Additional Information

No response

Edit: reproduction from the most recent commit

@dummdidumm
Copy link
Member

I see that you're using bun - is it not running the prepare script for some reason? My suspicsion is that that script is not run, which is why those are types are never generated. What happens if you run the build script (which should generate the types), and then check?

@fel1x-developer
Copy link
Author

I see that you're using bun - is it not running the prepare script for some reason? My suspicsion is that that script is not run, which is why those are types are never generated. What happens if you run the build script (which should generate the types), and then check?

bun run prepare
$ svelte-kit sync || echo ''bun run build
$ vite build && bun run prepack
vite v6.2.2 building SSR bundle for production...
✓ 159 modules transformed.
vite v6.2.2 building for production...
✓ 141 modules transformed.
.svelte-kit/output/client/_app/version.json                         0.03 kB │ gzip:  0.05 kB
.svelte-kit/output/client/.vite/manifest.json                       2.95 kB │ gzip:  0.58 kB
.svelte-kit/output/client/_app/immutable/assets/2.BnWmujQL.css      0.04 kB │ gzip:  0.06 kB
.svelte-kit/output/client/_app/immutable/entry/start.D_ORPpFE.js    0.08 kB │ gzip:  0.09 kB
.svelte-kit/output/client/_app/immutable/chunks/NIZ21t0L.js         0.32 kB │ gzip:  0.25 kB
.svelte-kit/output/client/_app/immutable/nodes/0.CBlHV_J2.js        0.33 kB │ gzip:  0.24 kB
.svelte-kit/output/client/_app/immutable/chunks/MEPW_APn.js         0.97 kB │ gzip:  0.62 kB
.svelte-kit/output/client/_app/immutable/chunks/BBmf3TEU.js         1.00 kB │ gzip:  0.57 kB
.svelte-kit/output/client/_app/immutable/nodes/1.AoBglGAZ.js        1.04 kB │ gzip:  0.61 kB
.svelte-kit/output/client/_app/immutable/chunks/C-_F0pL2.js         1.67 kB │ gzip:  0.95 kB
.svelte-kit/output/client/_app/immutable/chunks/D6tdrY-o.js         3.20 kB │ gzip:  1.52 kB
.svelte-kit/output/client/_app/immutable/entry/app.vEwLjz8R.js      6.50 kB │ gzip:  3.09 kB
.svelte-kit/output/client/_app/immutable/chunks/DAHvuMGr.js        12.64 kB │ gzip:  5.13 kB
.svelte-kit/output/client/_app/immutable/chunks/DzLSSGGM.js        32.36 kB │ gzip: 12.61 kB
.svelte-kit/output/client/_app/immutable/nodes/2.B21DaRUe.js      208.72 kB │ gzip: 72.06 kB
✓ built in 443ms
.svelte-kit/output/server/.vite/manifest.json                         2.00 kB
.svelte-kit/output/server/_app/immutable/assets/_page.BnWmujQL.css    0.04 kB
.svelte-kit/output/server/entries/fallbacks/layout.svelte.js          0.17 kB
.svelte-kit/output/server/internal.js                                 0.31 kB
.svelte-kit/output/server/chunks/escaping.js                          0.53 kB
.svelte-kit/output/server/chunks/equality.js                          0.77 kB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js           1.52 kB
.svelte-kit/output/server/entries/pages/_page.svelte.js               1.56 kB
.svelte-kit/output/server/chunks/index.js                             2.54 kB
.svelte-kit/output/server/chunks/exports.js                           6.89 kB
.svelte-kit/output/server/chunks/internal.js                         42.71 kB
.svelte-kit/output/server/index.js                                  105.50 kB
✓ built in 1.17s

Run npm run preview to preview your production build locally.

> Using @sveltejs/adapter-vercel
  ✔ done
$ svelte-kit sync && svelte-package && publint
src/lib -> dist
Running publint v0.3.9 for @sveltejs-labs/chart.js...
Packing files with `bun pack`...
Linting...
All good!bun run check
$ svelte-kit sync && svelte-check --tsconfig ./tsconfig.json

====================================
Loading svelte-check in workspace: /Users/minsoochoo/WebstormProjects/chartjs
Getting Svelte diagnostics...

/Users/minsoochoo/WebstormProjects/chartjs/src/lib/utils/chart.svelte.ts:2:31
Error: Cannot find module './$types' or its corresponding type declarations.
import type { Action } from 'svelte/action';
import type { Snapshot } from './$types';
import type { ChartData, ChartOptions, ChartTypeRegistry, UpdateMode } from 'chart.js';


====================================
svelte-check found 1 error and 0 warnings in 1 file
error: script "check" exited with code 1

Using npm causes the same problem

rm -rf node_modulesnpm i
npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated @humanwhocodes/[email protected]: Use @eslint/config-array instead
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated @humanwhocodes/[email protected]: Use @eslint/object-schema instead
npm warn deprecated [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.

> @sveltejs-labs/[email protected] prepare
> svelte-kit sync || echo ''


added 605 packages, and audited 606 packages in 31s

164 packages are looking for funding
  run `npm fund` for details

4 vulnerabilities (2 low, 2 moderate)

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.npm run check

> @sveltejs-labs/[email protected] check
> svelte-kit sync && svelte-check --tsconfig ./tsconfig.json


====================================
Loading svelte-check in workspace: /Users/minsoochoo/WebstormProjects/chartjs
Getting Svelte diagnostics...

/Users/minsoochoo/WebstormProjects/chartjs/src/lib/utils/chart.svelte.ts:2:31
Error: Cannot find module './$types' or its corresponding type declarations.
import type { Action } from 'svelte/action';
import type { Snapshot } from './$types';
import type { ChartData, ChartOptions, ChartTypeRegistry, UpdateMode } from 'chart.js';


====================================
svelte-check found 1 error and 0 warnings in 1 file

@dummdidumm
Copy link
Member

Closing since this works as expected - you are using ./$types within a folder that is not part of routes. Those type imports only working within src/routes, as they are all related to the current page you're on according to the file-based routing.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants