Skip to content

@types/babel__core should probably be a dependency instead of a devDependency #506

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

Open
DetachHead opened this issue Apr 21, 2022 · 2 comments

Comments

@DetachHead
Copy link

Describe the bug
when attempting to type check svelte.config.js with typescript, i get the following error:

> tsc -p tsconfig.json

node_modules/svelte-preprocess/dist/types/options.d.ts:4:55 - error TS7016: Could not find a declaration file for module '@babel/core'. 'C:/Users/amogus/IdeaProjects/network-chungus/node_modules/@babel/core/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/babel__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@babel/core';`

4 import type { TransformOptions as BabelOptions } from '@babel/core';
                                                        ~~~~~~~~~~~~~

because @types/babel__core is required by users downstream (if they're using typescript), i'd suggest moving it to dependencies instead of devDependencies. otherwise users will have to manually add @types/babel__core to their package.json to get rid of the errors.

To Reproduce

// svelte.config.js
import sveltePreprocess from 'svelte-preprocess'

/** @type {import('@sveltejs/kit').Config} */
const config = {
    preprocess: sveltePreprocess({ sourceMap: true }),
    compilerOptions: {
        enableSourcemap: true,
    },
}

export default config
// tsconfig.json
{
    "extends": "@tsconfig/svelte/tsconfig.json",
    "compilerOptions": {
        "allowJs": true,
        "checkJs": true,
        "skipLibCheck": false //although changing this to true would also fix the problem, i try to avoid it at all costs because it's dangerous
    }
}

Expected behavior
all dependencies required for type checking downstream are included in dependencies

Information about your project:

  • Your browser and the version: n/a

  • Your operating system: n/a

  • svelte-preprocess version: 4.10.5

  • Whether your project uses Webpack or Rollup: vite (which i think uses rollup? idk im new)

Additional context

see openapi-library/OpenAPIValidators#258 (comment) for more info

@dummdidumm
Copy link
Member

Mhm this is tricky. We don't want to do that because these types are only relevant when using the babel preprocessor. But since the type definitions are static, we can't model that. Maybe we need to add comments that tell TS to ignore the type errors.

@DetachHead
Copy link
Author

Maybe we need to add comments that tell TS to ignore the type errors.

unfortunately that probably won't work due to microsoft/TypeScript#38628

but yeah i agree it's a tough situation, ideally you could have conditional dependencies based on whether you're using the babel preprocessor but i don't think npm supports such a thing

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

2 participants