6

I am using Vite with a Typescript React project. I have jest tests in my project as well.

When I run vite build it seems to be compiling and bundling my test files. I have some stubbed out tests that I plan to get to with some compiling errors right now.

Example when I run yarn build which has tsc && vite build

> yarn build
yarn run v1.22.17
warning package.json: No license field
$ tsc && vite build
src/core/utils/numberUtils.spec.ts:1:1 - error TS1208: 'numberUtils.spec.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.

1 describe('numberUtils - ', () => {
  ~~~~~~~~


Found 1 error.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Looking at it a little more, it's actually Typescript that is throwing the errors when I run tsc, though I still am unsure if Vite is bundling it.

How do I fix tsc errors when using vite?

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Carson Wood
  • 1,174
  • 3
  • 14
  • 23

1 Answers1

4

As you noticed, the error is coming from tsc and not vite build. Vite is not trying to bundle your test files, it is typescript that is trying to typecheck them. Since the tsc command fails with errors, vite build never even runs.

Typescript lets you ignore files matching a pattern: How to exclude files ending in '.spec.ts' in tsconfig.json

tsconfig.json

"exclude": [
    "**/*.spec.ts"
]
pfg
  • 2,348
  • 1
  • 16
  • 37