Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Vite says the module has no export named 'default'

ErrorUncaught SyntaxError: The requested module '/src/utils.js' does not provide an export named 'default'

Short answer

The browser linked your import against a module that has no default export. Either the file only has named exports, or a CommonJS package hands over its whole module.exports object, or a linked package was never converted to ESM by Vite. Read the failing import first, then check how the package exports its value.

  • Applies to Vite 8, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    The path in the error says which module is the problem. A path under /src is your own file. A path under node_modules/.vite/deps is a dependency.

    grep -n "export" src/utils.js
  2. 2Match what you see, then jump to its fix

    1. 1The path in the error starts with /src and the file contains export { ... } or export constYour own file has only named exportsFix
    2. 2The path is under node_modules and the package ships CommonJS or UMD; the default import is an object or undefinedA CommonJS package and two ideas of what 'default' meansFix
    3. 3The package comes from npm link or a workspace and is not exported as ESMA linked or monorepo package is not pre-bundled as ESMFix

What does the error look like?

  • Uncaught SyntaxError: The requested module '/src/utils.js' does not provide an export named 'default'
  • The requested module '/node_modules/.vite/deps/some-package.js' does not provide an export named 'default'

Cause 1 of 3

Your own file has only named exports

1Check

A module may have many named exports but only one default one. An import without braces asks for the default.

grep -n "export" src/utils.js

2Fix

Import by name with braces, or add a default export to the file.

// utils.js
export function formatDate(d) { return d.toISOString() }

// consumer
import { formatDate } from './utils.js'

3Verify

Reload the page; the SyntaxError should be gone.

npx vite

Confirmed by developer.mozilla.org

Did this fix it?

Cause 2 of 3

A CommonJS package and two ideas of what 'default' means

1Check

A CommonJS file has no real default export. Babel-style tools use module.exports.default when __esModule is set, while Node-style tools return all of module.exports. Print what you actually get.

import raw from 'some-package'
console.log(raw)

2Fix

Accept both shapes in your own code, and report the problem to the package if it keeps happening. publint can show whether the package is published correctly.

import raw from 'some-package'
const lib =
  typeof raw === 'object' && raw !== null && raw.__esModule ? raw.default : raw

3Verify

Log lib and confirm it is the function or object you expect.

console.log(typeof lib)

Confirmed by rolldown.rs

Did this fix it?

Cause 3 of 3

A linked or monorepo package is not pre-bundled as ESM

1Check

Vite converts CommonJS dependencies to ESM during pre-bundling, but linked packages that are not ESM are not discovered on their own.

ls node_modules/.vite/deps

2Fix

List the package in optimizeDeps.include and restart with --force so the cache is rebuilt.

// vite.config.js
import { defineConfig } from 'vite'
export default defineConfig({
  optimizeDeps: { include: ['linked-dep'] },
})

# shell
npx vite --force

3Verify

The deps folder should now contain the package and the import should resolve.

ls node_modules/.vite/deps | grep linked-dep

Confirmed by vite.dev

Did this fix it?

How do I stop it coming back?

  • Prefer named exports in your own modules so imports fail loudly and keep their names.
  • Run publint on packages you maintain before publishing.
  • Restart with --force after changing a linked package.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.