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

Minify broke the build whether it is 'terser' or 'esbuild' #16576

Closed
7 tasks done
coolcorexix opened this issue May 2, 2024 · 1 comment
Closed
7 tasks done

Minify broke the build whether it is 'terser' or 'esbuild' #16576

coolcorexix opened this issue May 2, 2024 · 1 comment
Labels
invalid This doesn't seem right

Comments

@coolcorexix
Copy link

Describe the bug

So I was making a chrome extension which use vite to bundle a function to inject a component to the existing DOM of Gmail

If I turn off minify in vite.config.js by minify: off the code work fine but I need it to avoid naming conflict and reverse-engineering. I try building my app with webpack and things worked too.

The error was

image

Here's my branch, the sub-repo is gmail-button-vite-app: https://github.com/coolcorexix/mond/tree/test-new-saleshood-extension

Reproduction

https://github.com/coolcorexix/mond/tree/test-new-saleshood-extension

Steps to reproduce

Get static file ready

pnpm install
pnpm run -F gmail-button-vite-app  build
pnpm run -F gmail-button-vite-app  preview 

Load unpacked extension in any chromium-based browser
Go to https://gmail.com
You should see the error in the console in the middle of a bunch of "Adding button" log

System Info

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M1
    Memory: 171.95 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.5.0 - ~/.nvm/versions/node/v20.5.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v20.5.0/bin/yarn
    npm: 9.8.0 - ~/.nvm/versions/node/v20.5.0/bin/npm
    pnpm: 8.6.3 - ~/Library/pnpm/pnpm
    bun: 1.0.2 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 124.1.65.122
    Chrome: 124.0.6367.118
    Safari: 17.4.1

Used Package Manager

pnpm

Logs

No response

Validations

@sapphi-red
Copy link
Member

Vite outputs a module script, but you're injecting it as a classic script.
https://github.com/coolcorexix/mond/blob/12f3e703cfffa87c55de4ec9f364c1584fccc898/index.js#L1-L6
You'll need to set scriptElement.type = 'module'. (or change the output format)

@sapphi-red sapphi-red added invalid This doesn't seem right and removed pending triage labels May 2, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants