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.

Describe the bug

In some scenarios Vite seems to not be able to handle CJS dependencies.

This only happens with Vite 3.

Reproduction

https://github.com/brillout/vite-3-cjs-bug

Additional Context

vikepress includes .ts, .css, and .svg files: that’s because Node.js cannot handle import './someStyles.css' nor import emojiUrl from './someEmoji.svg', which means that vikepress cannot be externalized. That’s why vikepress publishes its source files to npm.

Note that including source files is also a common practice in SvelteKit’s ecosystem.

System Info

System:
    OS: Linux 5.10 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (2) x64 Intel(R) Celeron(R) N4020 CPU @ 1.10GHz
    Memory: 509.13 MB / 2.71 GB
    Container: Yes
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 18.0.0 - ~/.config/nvm/versions/node/v18.0.0/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.6.0 - ~/.config/nvm/versions/node/v18.0.0/bin/npm
  Browsers:
    Firefox: 97.0.1
  npmPackages:
    vite: ^2.8.4 => 3.0.0-beta.5

Used Package Manager

pnpm

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
brilloutcommented, Jul 8, 2022

Fixed in beta.9 🎉.

0reactions
patak-devcommented, Jul 7, 2022

@stefanvanherwijnen we’re thinking about waiting until Vite 4 to enable ssr and build deps optimization so we can release v3 sooner. If you want to test, this PR may be what ends up reaching stable:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vite 3.0 is out!
In Vite 3, all of the templates got a new theme in line with the new docs. ... During build time, @rollup/plugin-commonjs is...
Read more >
Configuring Vite
Configuring Vite #. When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project...
Read more >
Building for Production - Vite
When it is time to deploy your app for production, simply run the vite build command. By default, it uses <root>/index.html as the...
Read more >
Server-Side Rendering - Vite
The Vite playground contains example SSR setups for Vue 3 and React, ... 'text/html' }).end(html) } catch (e) { // If an error...
Read more >
Configuring Vite
Using these as variable names will result in an error: ... A workaround is to use CJS build outputs until ESM has better...
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