Closed johandalabacka closed 1 year ago
This was an upstream issue. I created an issue to rollup (https://github.com/rollup/rollup/issues/4751).
@johandalabacka , I did run your code, all u need to do is to add the base property to vite.config.js, it works on production as well // pasted here import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' export default defineConfig({ base: "./", plugins: [vue()], })
@Foster0123 Thanks. I try it
Update: I tried your fix but it didn't make any difference. api.greetings.hello() is still removed. I don't think base has anything to do with how treeshaking works. It set the base-url used for finding assets and etc
did u run the build on a server ??
u need a local server to serve the build else the script will be blocked by CORS
@Foster0123 I'm not sure what you mean. Running yarn build and then yarn preview starts a local server serving the built files. And I watched in the built code and the call is missing. I also tried http-server dist
and this didn't work either. The output in the log is
App.hello
hi from greetings
with hello from greetings
is missing in both cases
yeah it seems to be a vite build issue, most likely a bug
Closing as this is fixed in rollup 3.7.5.
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
api/index.js
api/greetings.js
Reproduction
https://github.com/johandalabacka/vite4-build-error
Steps to reproduce
Download repo and install
Open http://localhost:5173/ and pressing the button and the output in the log is:
But if we build it:
Open http://localhost:4173/ and press the button and now output in the log is only:
System Info
Used Package Manager
yarn
Logs
No response
Validations