question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Requested module does not provide export named 'default'

See original GitHub issue

Environment

  • Node Version: v14.16.0
  • Nuxt Version: 3.0.0
  • Package Manager: npm@7.17.0
  • Bundler: Vite

Reproduction

here you can see a very simple reproduction link https://stackblitz.com/edit/github-nl4dyg?file=app.vue

npm run dev

Describe the bug

I’m trying to use class-validator packages. first I faced a problem mentioned here and solved it by adding this package to build.transpile in nuxt.config.ts file.

then this error starts to show up SyntaxError: The requested module '/_nuxt/node_modules/validator/lib/isLatLong.js?v=cba03522' does not provide an export named 'default' the validator package is one of class-validator dependencies.

the weird part is that the code runs perfectly on the server process

and the error only occurs on the browser and it works fine on both server and browser in production mode!

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
danielroecommented, Jan 15, 2022

This seems to be solved by disabling ‘optimizeDeps’ on this module:

import { defineNuxtConfig } from 'nuxt3'

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
  build: {
    transpile: ["class-validator"],
  },
  vite: {
    optimizeDeps: {
      exclude: ['class-validator']
    }
  }
})
2reactions
abdulhadi-lababidicommented, Jan 16, 2022

I found a workaround for this issue by using Webpack instead of Vite.

you can enable Webpack by setting vite to false in nuxt.config.ts

export default defineNuxtConfig({
  vite: false
})

but you should remove the class-validator package from build.transpile

Read more comments on GitHub >

github_iconTop Results From Across the Web

Requested module does not provide export named 'default'
To solve the error "The requested module does not provide an export named 'default'", use the default keyword when exporting a value from...
Read more >
42 - Stack Overflow
Uncaught SyntaxError: The requested module './add.js' does not provide an export named 'add' ; <head> ; <script type="module" src="app.js"> ; </ ...
Read more >
How to Solve does not provide an export named 'default'
To solve the error 'does not provide an export name default' in JavaScript, use the default keyword to make it the default export...
Read more >
Misleading error that module does not provide export #32137
SyntaxError: The requested module './dependency.cjs' is a CommonJS module, which can only provide a default export, not named exports, to an ES ...
Read more >
vite the requested module does not provide an export named ...
Dec 24, 2021 ... The reason it didn't work is that Vue provides a named export, whereas you are trying to import it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found