Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite removes source code on MacOS #11020

Closed
7 tasks done
sheremet-va opened this issue Nov 21, 2022 · 9 comments
Closed
7 tasks done

Vite removes source code on MacOS #11020

sheremet-va opened this issue Nov 21, 2022 · 9 comments
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@sheremet-va
Copy link
Member

Describe the bug

When building browser package, I expect code from client/main.ts to be bundled inside assets, but instead Vite omits it.

Reproduction

https://github.com/vitest-dev/vitest/tree/main/packages/browser

Steps to reproduce

Only reproducible on MacOS.

pnpm install
pnpm build
cd packages/browser

Inside dist/client folder you should see html file and assets folder. I expect client/main.ts code to be inside assets/index.[hash].js file, but instead it contains only polyfill for preload.

System Info

System:
    OS: macOS 13.0
    CPU: (8) arm64 Apple M1
    Memory: 67.31 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.1/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.1/bin/npm
  Browsers:
    Chrome: 107.0.5304.110
    Firefox: 107.0
    Safari: 16.1

Used Package Manager

pnpm

Logs

No response

Validations

@sodatea
Copy link
Member

sodatea commented Nov 22, 2022

@userquin
Copy link
Contributor

@sodatea why Windows is working with Node 16.17.0? I build the package and the code is there...

D:\work\projects\userquin\GitHub\antfu\vitest>node --version
v16.17.0

D:\work\projects\userquin\GitHub\antfu\vitest>pnpm vite --version
vite/3.2.3 win32-x64 node-v16.17.0

vitest-browser-main-asset

@sheremet-va
Copy link
Member Author

Yes, why windows works, and why „sideEffects“ matter when bundling source code? There is no other way in Vite to import my code.

@sodatea
Copy link
Member

sodatea commented Nov 22, 2022

I think it's because the actual entry file passed to Rollup is index.html and it tree-shakes its dependencies?
But I don't know

  1. whether sideEffects should be taken into account in this case. My gut tells me it should not.
  2. why it doesn't tree-shake on Windows.

@userquin
Copy link
Contributor

@sodatea I've refactored browser package structure and now it seems to be working properly: maybe Vite with rollup.config and vite.config mixing builds? I mean, we've 2 builds: rollup.config is configured to build node stuff (the entry point is node/index.ts, in the PR moved to src/node folder), and vite.config to build client stuff (in the PR, I've moved all vite stuff inside src/client folder changing the root in the build script): vitest-dev/vitest#2367

@powerfulyang
Copy link

I think it's because the actual entry file passed to Rollup is index.html and it tree-shakes its dependencies? But I don't know

  1. whether sideEffects should be taken into account in this case. My gut tells me it should not.
  2. why it doesn't tree-shake on Windows.

when use relative path, <script type="module" src="./client/main.ts"></script> will reproduce the bug, but it can't be triggered by absolute path <script type="module" src="/client/main.ts"></script>. By the way, this bug only appear in unix or linux.

@fregante
Copy link

I'm pretty sure this is a duplicate of:

@fregante fregante mentioned this issue Feb 13, 2023
7 tasks
@patak-dev
Copy link
Member

@sheremet-va this seems to be fixed to me. Could you check on your side?
I thought that vite@4.3.0-beta.2 fixed this one after #12628, but I'm not able to reproduce it in 4.2.1 (maybe the fix in rollup did the trick here). Or I'm not testing it correctly 👀

@patak-dev patak-dev added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Apr 7, 2023
@patak-dev
Copy link
Member

I think this is indeed a duplicate of #10735. I just sent a PR for it, let's keep discussing on the other issue.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

6 participants