Skip to content

Missing dependencies in svelte/compiler type definitions #3397

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

Closed
luiz opened this issue Aug 12, 2019 · 6 comments
Closed

Missing dependencies in svelte/compiler type definitions #3397

luiz opened this issue Aug 12, 2019 · 6 comments

Comments

@luiz
Copy link

luiz commented Aug 12, 2019

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.

@Rich-Harris
Copy link
Member

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

@luiz
Copy link
Author

luiz commented Aug 16, 2019

I've made an attempt in a new PR referenced above. I believe it's not very robust, but I could not find any other way to do that. I looked for a way to make Typescript bundle included files, but didn't find anything.

@luiz luiz closed this as completed Aug 16, 2019
@AlexMost
Copy link

AlexMost commented Apr 5, 2020

The issue is closed, but this still fails for me ... Here was my workaround to overcome this trouble
ttag-org/ttag-cli@ecd7ade

@dummdidumm
Copy link
Member

dummdidumm commented Apr 20, 2020

Issue reoccurs because while merging #3539 the bug was reintroduced because the fix was undone: b9f1484#diff-ff6e5f22a9c7e66987b19c0199636480 . I also think just reimplementing the fix will not work anymore. estree-walker has changed how it exports its typings. They are also no longer self-contained and now depend on estree typings.

If the typings should be included in svelte it would mean including all of estrees-typings as well as manipulating/fixing the estree-walker-types (remove declare, remove estree imports). I don't know if that's the best way to go in the long run. Maybe adding some type of peerDependency and a note in the docs would be better.

dummdidumm pushed a commit to dummdidumm/svelte that referenced this issue Apr 20, 2020
@razshare
Copy link

razshare commented May 2, 2022

Any news on this or is there a different issue tracking the bug?

@SyMind
Copy link

SyMind commented Jan 18, 2023

@Rich-Harris I think this rollup plugin can resolve this problem.
https://github.com/Swatinem/rollup-plugin-dts

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

No branches or pull requests

6 participants