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.

Vite 4 is removing import

See original GitHub issue

Describe the bug

If I have an import in App.vue which is a “double” import. The imported method is removed on build. While developing it works but it is gone on build. It works if I use vite@^3. I also works if I import is imported directly

App.vue

import api from './api/index.js'
import greetings from './api/greetings.js'


methods: {
  hello() {
    console.log('App.hello)
    api.greetings.hello() // <--- this is removed on build. Using yarn dev works
    greetings.hi() // <--- this is not removed on build
  }
}

api/index.js

import * as greetings from './greetings.js'
export default {
  greetings
}

api/greetings.js

export function hello () {
  console.log('hello from greeings.js')
}

export function hi () {
  console.log('hi from greeings.js')
}

Reproduction

https://github.com/johandalabacka/vite4-build-error

Steps to reproduce

Download repo and install

git clone https://github.com/johandalabacka/vite4-build-error
cd vite4-build-error
yarn install
yarn dev

Open http://localhost:5173/ and pressing the button and the output in the log is:

App.hello
hello from greetings
hi from greetings

But if we build it:

yarn build
yarn preview

Open http://localhost:4173/ and press the button and now output in the log is only:

App.hello
hi from greetings

System Info

System:
    OS: macOS 13.0.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 71.13 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.0 - ~/.nvm/versions/node/v18.12.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.12.0/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.0/bin/npm
  Browsers:
    Chrome: 108.0.5359.98
    Firefox: 107.0.1
    Safari: 16.1
  npmPackages:
    @vitejs/plugin-vue: ^4.0.0 => 4.0.0 
    vite: ^4.0.0 => 4.0.1

Used Package Manager

yarn

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
sapphi-redcommented, Dec 17, 2022

Closing as this is fixed in rollup 3.7.5.

0reactions
Foster0123commented, Dec 16, 2022

yeah it seems to be a vite build issue, most likely a bug

Read more comments on GitHub >

github_iconTop Results From Across the Web

Features | Vite
Use the Type-Only Imports and Export syntax to avoid potential problems like type-only imports being incorrectly bundled, for example:.
Read more >
Removal of empty chunks doesn't update all imports #8330
In Astro we are updating to use vite:css-post for bundling instead of doing it our own thanks to the new viteMetadata property.
Read more >
How to get Vite to not import/bundle an external dependency
Note that I am removing all imports -- if you only need to remove some then your postprocess regex will differ. Install the...
Read more >
Migrating from Create React App (CRA) to Vite
For example: import { ReactComponent as Logo } from './logo.svg' . 2. Create Vite config file. Create a ...
Read more >
How To Set Up a React Project with Vite - DigitalOcean
Step 1 — Creating a Vite Project · Step 2 — Starting the Development Server · Step 3 — Previewing Your App from...
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