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

fix: Add support for vite.config.ts #6140

Merged
merged 1 commit into from
Aug 22, 2022

Conversation

bfanger
Copy link
Contributor

@bfanger bfanger commented Aug 21, 2022

When using a vite.config.ts (instead of a vite.config.js) TypeScript generates an error:

error TS2307: Cannot find module '@sveltejs/kit/vite' or its corresponding type declarations.

1 import { sveltekit } from "@sveltejs/kit/vite";
                            ~~~~~~~~~~~~~~~~~~~~

Found 1 error in vite.config.ts:1

Adding the vite.config.ts to the includes fixes this issue.

Also closes #5443

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

TS2307: Cannot find module '@sveltejs/kit/vite' or its corresponding type declarations.

1 import { sveltekit } from "@sveltejs/kit/vite";
                            ~~~~~~~~~~~~~~~~~~~~

Found 1 error in vite.config.ts:1
@changeset-bot
Copy link

changeset-bot bot commented Aug 21, 2022

🦋 Changeset detected

Latest commit: 2655935

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris Rich-Harris merged commit fca688c into sveltejs:master Aug 22, 2022
@Rich-Harris
Copy link
Member

thanks!

@Layendan
Copy link

Layendan commented Aug 23, 2022

I am still getting this error, even in the new version.

I ran vite build as well as reloaded the window after updating; however, the error still appears.

Although I doubt that the missing module error is linked to this issue. They did appear in my repository at the same time.

image

Gihub Repo

Edit: File in question

System:
    OS: macOS 12.5.1
    CPU: (8) arm64 Apple M1
    Memory: 103.64 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.0.0 - /usr/local/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.6.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 104.0.5112.101
    Safari: 15.6.1
  npmPackages:
    @sveltejs/adapter-static: ^1.0.0-next.39 => 1.0.0-next.39 
    @sveltejs/kit: 1.0.0-next.429 => 1.0.0-next.429 
    svelte: ^3.49.0 => 3.49.0 
    vite: ^3.0.9 => 3.0.9

Update: I have changed my tsconfig.json from

{
  "compilerOptions": {
    "moduleResolution": "node",
    "module": "esnext",
    "lib": ["es2021", "DOM"],
    "target": "es2020",
    "importsNotUsedAsValues": "error",
    "preserveValueImports": true,
    "isolatedModules": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "baseUrl": ".",
    "allowJs": true,
    "checkJs": true,
    "paths": {
      "$lib": ["src/lib"],
      "$lib/*": ["src/lib/*"]
    }
  },
  "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"],
  "extends": "./.svelte-kit/tsconfig.json"
}

to

{
	"extends": "./.svelte-kit/tsconfig.json",
	"compilerOptions": {
		"allowJs": true,
		"checkJs": true,
		"esModuleInterop": true,
		"forceConsistentCasingInFileNames": true,
		"resolveJsonModule": true,
		"skipLibCheck": true,
		"sourceMap": true,
		"strict": true
	}
	// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
	//
	// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
	// from the referenced tsconfig.json - TypeScript does not merge them in
}

And that seemed to fix it.

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

Successfully merging this pull request may close these issues.

Add vite.config.ts to generated tsconfig include
5 participants