Vite 4 is removing import
See original GitHub issueDescribe 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 9 months ago
- Comments:7 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Closing as this is fixed in rollup 3.7.5.
yeah it seems to be a vite build issue, most likely a bug