Skip to content
Wrong Type Imports Are Breaking Your Full-Stack React App

Wrong Type Imports Are Breaking Your Full-Stack React App

Updated: at 06:49 AM

You're running browser tests in your Next.js app with Vitest, and suddenly you're hit with a cascade of Vite pre-transform errors. This time for me it was a next-auth import type error and I couldn't figure out why, since I was importing the types only.

The error message pointed to a seemingly innocent import statement, but the tests kept failing. If you're using next-auth with TypeScript, there's a good chance you've encountered this exact problem.

The issue comes from a subtle but critical difference in how TypeScript handles type imports, and how bundlers like Vite interpret them.

The next-auth import type error

When running browser tests with Vitest, you might see errors like this next-auth import type error:

[vite] (client) Pre-transform error: No known conditions for "./adapters" specifier in "next-auth" package
  Plugin: vite:import-analysis
  File: /path/to/src/server/db/schema.ts:25:36
  20 |  import {} from "next-auth/adapters";
     |                  ^

The error repeats multiple times, and while your tests might still pass, these warnings clutter your output and indicate a deeper bundling issue.

The Culprit

The problem is in how you're importing types from next-auth/adapters. You might have written:

import { type AdapterAccount } from "next-auth/adapters";

This looks correct at first glance. You're using the type keyword, so TypeScript knows it's a type import.

However, this syntax has a different meaning to bundlers like Vite.

The Solution

Change your import to use the import type syntax instead:

import type { AdapterAccount } from "next-auth/adapters";

This single change eliminates the Vite pre-transform errors and ensures your bundler handles the import correctly.

Understanding the Difference

There are two ways to import types in TypeScript, and they behave differently.

import type { ... } - Type-Only Import

import type { AdapterAccount } from "next-auth/adapters";

This is a type-only import statement. The entire import is marked as type-only, which means:

import { type ... } - Value Import with Type-Only Named Import

import { type AdapterAccount } from "next-auth/adapters";

This is a value import statement with a type-only named import. Even though the specific import is marked as type-only:

Why This Matters for Vite and Bundlers

Modern bundlers like Vite perform static analysis on your code before transformation. When they encounter an import statement, they need to understand:

With import { type ... }, the bundler sees a value import and may attempt to analyze the module, even if the specific named export is type-only.

For packages like next-auth that use conditional exports (like "./adapters"), this analysis can fail when the bundler can't determine the correct export condition for the build target.

Best Practices

When importing types in TypeScript, especially in projects using Vite, Webpack, or other modern bundlers:

ESlint

Looks like there's an ESlint rule @typescript-eslint/consistent-type-exports that can help you catch these import statements. Check out Consistent Type Imports and Exports: Why and How.

Conclusion

The difference between import type { ... } and import { type ... } might seem minor, but it has real implications for how bundlers process your code.

When working with Next.js, React, and packages like next-auth, using the correct type import syntax prevents bundler errors and keeps your test output clean.

If you're seeing Vite pre-transform errors related to type imports, check your import statements and convert them to use import type syntax. Your bundler—and your future self—will thank you while you avoid the next-auth import type error altogether.

For deeper dives, see the official docs for the NextAuth adapter API, the TypeScript import type syntax, and Vite's guidance on conditional exports.

And here you can read my other posts on similar topics: Next.js, TypeScript, and Vitest.


Next Steps: Review your codebase for type imports and standardize on import type syntax. This small change will improve your build performance and eliminate unnecessary bundler warnings.

Thanks for reading!

React Testing Library Crash Course

React Testing Library Crash Course: Learn to Test React Components takes you on a hands-on, practical journey to mastering component testing in React. From setting up your testing environment to tackling advanced scenarios, every chapter is written in a bite-sized, actionable style.

Learn More
React Testing Library Crash Course

What to Read Next