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

TypeScript definition reference dist dir not bundled in the npm #2874

Closed
sanderhahn opened this issue May 26, 2019 · 9 comments · Fixed by #2876
Closed

TypeScript definition reference dist dir not bundled in the npm #2874

sanderhahn opened this issue May 26, 2019 · 9 comments · Fixed by #2876

Comments

@sanderhahn
Copy link
Contributor

Errors during compilation:

node_modules/svelte/store.d.ts:1:15 - error TS2307: Cannot find module './dist/store'.

1 export * from './dist/store';
                ~~~~~~~~~~~~~~
@Harald-1
Copy link
Contributor

Harald-1 commented May 26, 2019

I cannot reproduce it.
I took a fresh copy of the repo (branch master), then "npm install" and "npm run build".
node v10.15.3, npm 6.4.1, macOS 10.14.5

@sanderhahn
Copy link
Contributor Author

You can reproduce it by creating a new project and adding svelte as dependency.

@SleepyWerewolf
Copy link
Contributor

Opened a PR for a simple fix (see above), though tbh I'm not sure why compiled JS is left in the root dir while generated types are put in dist. I would suggest putting all generated artifacts in dist, as this keeps your working directory clean. Not going to address that with this PR though.

@Rich-Harris thoughts on the above?

@sanderhahn
Copy link
Contributor Author

Some absolute imports can't be resolved such as: 'svelte/internal' in easing.d.ts. However most references in TypeScript are relative and that does seems to work.

@Conduitry
Copy link
Member

Compiled JS is left at the root so that components can do things like import from svelte/store or svelte/animate, which is nicer than importing from svelte/dist/store.

@SleepyWerewolf
Copy link
Contributor

Ah I see, that makes sense. In that case, I think it'd be simpler to have declaration files generated at root as well. This is both more consistent, and allows us to remove the boilerplate-y export * from dist/thing'; in all the *.d.ts files

Rich-Harris added a commit that referenced this issue May 27, 2019
publish dist in order to get types
@Rich-Harris
Copy link
Member

I think it is slightly odd to have types in dist, but there is an argument for keeping them in their own subfolder even if it does result in a bunch of export * junk files — since declaration files don't get bundled, keeping them in root means you have a bunch of extra root directories like motion, parse etc. I think it's neater to have those in a single place (that can be gitignored by itself, and included in pkg.files by itself).

Best solution I think is to move dist to types. Will push up a commit momentarily

@Conduitry
Copy link
Member

👍 to having them live in types

@simonbuchan
Copy link

Compiled JS is left at the root so that components can do things like import from svelte/store or svelte/animate, which is nicer than importing from svelte/dist/store.

One option for this I've seen and used is for every package/foo you want to support, add a <repo>/foo/package.json with (at least) { "main": "../dist/foo.js" } (and also any other path fields like "module", "browser", "types", ...). It's most useful if you only have a few import paths you specifically want to support and lots of internal files you don't.

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

Successfully merging a pull request may close this issue.

6 participants