vite-ssg: 0.17.0 regression: named imports of commonjs lib raise error

Env Node v16.13.0 nite-ssg 0.17.0

While playing with vitesse templates, I try third party UI components, after pnpm i -S naive-ui, I import component by add one liner inside pages/index.vue import {NButton} from naive-ui while npm run build raise the following error:

[vite-ssg] An internal error occurred.
[vite-ssg] Please report an issue, if none already exists: https://github.com/antfu/vite-ssg/issues
file:///home/fang/Project/web/vitesse-main/.vite-ssg-temp/main.mjs:27
import { NButton } from "naive-ui";
         ^^^^^^^
SyntaxError: Named export 'NButton' not found. The requested module 'naive-ui' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

vite-ssg 0.16.2 give green light on npm run build

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (11 by maintainers)

Most upvoted comments

same proplem !! Isn’t this what evan recommended? Are there any other options besides cjs? Because I also need to use swiper,it only supports esm mode 😮‍💨 it’s really hard to choose😭

Try set

{
  ssgOptions: {
    format: 'cjs'
  }
}

in your vite.config.js with v0.17.2