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

svelte2tsx warning is confusing if typescript isn't installed #1889

Closed
Rich-Harris opened this issue Jul 12, 2021 · 0 comments · Fixed by #1903
Closed

svelte2tsx warning is confusing if typescript isn't installed #1889

Rich-Harris opened this issue Jul 12, 2021 · 0 comments · Fixed by #1903
Labels
bug Something isn't working

Comments

@Rich-Harris
Copy link
Member

Rich-Harris commented Jul 12, 2021

Describe the bug

I saw this error when running npm run package on a project:

You need to install svelte2tsx >=0.4.1 if you want to generate type definitions

svelte2tsx was installed; the source of the error was that typescript wasn't. We probably need to button up the error checking in https://github.com/sveltejs/kit/blob/master/packages/kit/src/core/make_package/index.js; emit_dts (which imports svelte2tsx) is called before transpile_ts (which imports typescript). This function...

async function try_load_svelte2tsx() {
try {
const svelte2tsx = (await import('svelte2tsx')).emitDts;
if (!svelte2tsx) {
throw new Error('Old svelte2tsx version');
}
return svelte2tsx;
} catch (e) {
throw new Error(
'You need to install svelte2tsx >=0.4.1 if you want to generate type definitions'
);
}
}

...could fail for any of the following reasons:

  1. typescript (or some other svelte2tsx peer dependency, theoretically) isn't installed
  2. svelte2tsx isn't installed
  3. svelte2tsx is out of date
  4. 🤷

At the moment, all errors are assumed to be 3. Also, it's maybe a bit odd that we throw an error, catch it, then immediately throw a different error, discarding the first.

Reproduction

npm init svelte@next my-package # select 'no' for typescript
cd my-package
npm i
npm run package

Logs

No response

System Info

System:
    OS: macOS 10.15.7
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 78.52 MB / 64.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.21.0 - ~/.nvm/versions/node/v12.21.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v12.21.0/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v12.21.0/bin/npm
  Browsers:
    Chrome: 91.0.4472.114
    Firefox: 89.0.2
    Safari: 13.1.3
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.125
    svelte: ^3.34.0 => 3.38.3

Severity

annoyance

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant