Vite says the module has no export named 'default'
Uncaught 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.
Fix it fast
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.js2Match what you see, then jump to its fix
- 1
The path in the error starts with /src and the file contains export { ... } or export constYour own file has only named exportsFix - 2
The 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
The package comes from npm link or a workspace and is not exported as ESMA linked or monorepo package is not pre-bundled as ESMFix
- 1
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.js2Fix
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 viteConfirmed by developer.mozilla.org
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 : raw3Verify
Log lib and confirm it is the function or object you expect.
console.log(typeof lib)Confirmed by rolldown.rs
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/deps2Fix
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 --force3Verify
The deps folder should now contain the package and the import should resolve.
ls node_modules/.vite/deps | grep linked-depConfirmed by vite.dev
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix