Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Typescript support broken with TS 4.5, can't find type declarations #270

Closed
phaer opened this issue Nov 18, 2021 · 6 comments
Closed

Typescript support broken with TS 4.5, can't find type declarations #270

phaer opened this issue Nov 18, 2021 · 6 comments
Labels

Comments

@phaer
Copy link

phaer commented Nov 18, 2021

Hi,

I am trying to create a new svelte project with typescript support, but the build and dev scripts seem unable to find type declarations for App.svelte, even though src/global.d.ts seem to be correct:

/// <reference types="svelte" />

To Reproduce

~/projects 
❯ npx degit sveltejs/template svelte-app
> cloned sveltejs/template#HEAD to svelte-app

~/projects 
❯ cd svelte-app/ && node scripts/setupTypeScript.js
Converted to TypeScript.

~/projects/svelte-app via ⬢ v16.11.1 
❯ npm install && npm run build

added 135 packages, and audited 136 packages in 2s

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

found 0 vulnerabilities

> svelte-app@1.0.0 build
> rollup -c


src/main.ts → public/build/bundle.js...
(!) Plugin typescript: @rollup/plugin-typescript TS2307: Cannot find module './App.svelte' or its corresponding type declarations.
src/main.ts: (1:17)

1 import App from './App.svelte';
                  ~~~~~~~~~~~~~~

(!) Plugin typescript: @rollup/plugin-typescript: Typescript 'sourceMap' compiler option must be set to generate source maps.
created public/build/bundle.js in 1.3s

Node Version

❯ node --version
v16.11.1
❯ npm --version
8.1.3
@phaer
Copy link
Author

phaer commented Nov 18, 2021

When I manually add /// <reference types="svelte" /> to main.ts i get a new error:

(!) Plugin typescript: @rollup/plugin-typescript TS2688: Cannot find type definition file for 'svelte'.
src/main.ts: (1:23)
``

So I suppose type declarations are just missing in general? Any hint on where to find them?

@dummdidumm
Copy link
Member

To rule out if it has to do with Typescript 4.5 which was just released: could you try to pin TS to 4.4 and try again?

@phaer
Copy link
Author

phaer commented Nov 18, 2021

@dummdidumm Thanks for your response and I can confirm it does work with typescript 4.4.4!

Additionally, I just was about to post that it also works with the following hardcoded path (with typescript 4.5)

/// <reference path="../node_modules/svelte/types/runtime/index.d.ts" />
import App from './App.svelte';

I am new to svelte and have been away from the whole JS ecosystem for a bit but will see if i find out more in typescripts changelog :)

@phaer phaer changed the title Typescript support seems to be broken, can't find type declarations Typescript support broken with TS 4.5, can't find type declarations Nov 18, 2021
@chrisolsen
Copy link

chrisolsen commented Nov 18, 2021

To rule out if it has to do with Typescript 4.5 which was just released: could you try to pin TS to 4.4 and try again?

This fixed the issue for me

dummdidumm added a commit that referenced this issue Nov 18, 2021
Related to #270, quick fix while we figure out what the problem is
@dummdidumm
Copy link
Member

This is an TypeScript issue, I created microsoft/TypeScript#46860 for that. I also created sveltejs/svelte#6937 which would solve this independently on our end.

@dummdidumm
Copy link
Member

This is fixed on our end through sveltejs/svelte#6937 , make sure to update to the latest version of Svelte and the error should go away. I still think this is a TS bug ultimately, but thankfully we can work around it with a change on our end. Closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants