profile
viewpoint

Ask questionsMissing dependencies in svelte/compiler type definitions

Describe the bug When compiling a Typescript code that uses svelte/compile, it fails because of missing libraries inside Svelte package.

Logs

node_modules/svelte/types/compiler/index.d.ts:4:22 - error TS2307: Cannot find module 'estree-walker'.

4 export { walk } from 'estree-walker';
                       ~~~~~~~~~~~~~~~

node_modules/svelte/types/compiler/preprocess/index.d.ts:1:27 - error TS2307: Cannot find module 'magic-string'.

1 import { SourceMap } from 'magic-string';
                            ~~~~~~~~~~~~~~

To Reproduce

  1. Create new Node project: npm init -y at empty folder
  2. Install Svelte and Tyepscript: npm i -D svelte typescript
  3. Configure Typescript:
{
	"compilerOptions": {
		"target": "es2016",
		"module": "commonjs",
		"outDir": "./build",
		"noEmitOnError": true,
		"noImplicitAny": true
	},
	"files": [
		"test.ts"
	]
}
  1. Create test.ts with the following import: import * as svelte from 'svelte/compiler'
  2. Run npx tsc

Expected behavior I should not need to manually install Svelte's dependencies; compilation should not fail.

Information about your Svelte project:

  • Svelte: 3.8.0
  • Typescript: 3.5.3

Severity Annoying. I can manually install Svelte's dependencies into my project.

sveltejs/svelte

Answer questions Rich-Harris

Is there a way to fix this by adding the types as dependencies, but not the packages?

useful!

Related questions

Javascript Interpolation in Styles via CSS Variables? hot 2
Svelte applications fail to load in IE 11. Similar loading issue with the main site svelte.dev hot 1
Uncaught TypeError: y.fragment.l is not a function hot 1
Increase elements when using a combination of await block and transition hot 1
Svelte applications fail to load in IE 11. Similar loading issue with the main site svelte.dev hot 1
Change body class via <svelte:body /> hot 1
Site: Svelte Cookbook/ Examples hot 1
Multiple components in one file - svelte hot 1
onMount Error: Function called outside component initialization hot 1
A way to see if slot prop is present hot 1
slot inside #if inside #each : TypeError cannot read property 'd' of null hot 1
unclear / difficult to import uuidv4 hot 1
Use <script type="application/ld+json"> in <svelte:head> hot 1
Error: 'default' is not exported when using babel + moment hot 1
Outros undefined when transitioning to another page hot 1
Github User Rank List