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.

0.17.0 regression: named imports of commonjs lib raise error

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
leosincommented, Feb 4, 2022

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😭

1reaction
antfucommented, Dec 19, 2021

Try set

{
  ssgOptions: {
    format: 'cjs'
  }
}

in your vite.config.js with v0.17.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js now supports named imports from CommonJS ...
The Workaround: What to do when named imports don't work for a CJS module. The good news is that, as the error message...
Read more >
rollup changelog
Fix a situation where invalid code was rendered when dynamically importing a module with synthetic named exports when preserving modules (#3738) ...
Read more >
steal-rollup | Yarn - Package Manager
Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library...
Read more >
node_modules/rollup/CHANGELOG.md · feature/npm-module
Generate proper namespace objects when dynamically importing external dependencies for AMD or CJS formats (#2954) · Fix dynamically imported variables not being ...
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
... fails with error message" status:RESOLVED resolution:OBSOLETE severity:normal ... Bug:96449 - "New: fusd A library and kernel module to create userpsace ...
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