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

Plugin legacy is not working as expected for replaceAll #15293

Closed
7 tasks done
alexookah opened this issue Dec 8, 2023 · 4 comments
Closed
7 tasks done

Plugin legacy is not working as expected for replaceAll #15293

alexookah opened this issue Dec 8, 2023 · 4 comments
Labels
cannot reproduce The bug cannot be reproduced pending triage

Comments

@alexookah
Copy link

alexookah commented Dec 8, 2023

Describe the bug

Hello,
I am using vite with react & viteRails.
I don't think the plugin legacy works as expected trying to include replaceAll and in Chrome 84 version it doesn't work.

I use a library in my project called camelCaseKeys.
This library depends on camelCase which has a function replaceAll.

My project was using babel:
{ "presets": ["@babel/preset-env", "@babel/preset-react"], "plugins": [ "@babel/plugin-syntax-dynamic-import", "@babel/plugin-proposal-class-properties", "@babel/plugin-transform-runtime" ] }

which I completely removed all babel in favor to plugin/legacy which kind of uses under the hood already.

I checked other relevant issues(issue 1, issue 2) about replaceAll since it's not included in the legacy by default.
So I used this configuration in my plugin/legacy. Not sure if this open issue is related.

legacy({
      targets: ['Chrome 63'],
      modernPolyfills: ['es.string.replace', 'es.string.replace-all', 'esnext.string.replace-all'], 
      polyfills: ['es.string.replace', 'es.string.replace-all', 'esnext.string.replace-all']
 }),

This configuration doesn't work for Chrome 84
I ended up including a polufill.io in the head to include replaceAll so that my project can run in older browser versions.

I want to know if vite_plugin_legacy covers also the node_module libraries usages for older browsers.

Reproduction

https://stackblitz.com/edit/vitejs-vite-cgggur?file=vite.config.js

Steps to reproduce

Created also a stackBlitz repro project: https://stackblitz.com/edit/vitejs-vite-cgggur?file=vite.config.js

System Info

Chrome 84 does not load replaceAll

Used Package Manager

yarn

Logs

No response

Validations

Copy link

stackblitz bot commented Dec 8, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@alexookah alexookah changed the title Plugin legacy is not working as expected for node_module libraries Plugin legacy is not working as expected for replaceAll Dec 8, 2023
@sapphi-red sapphi-red added the cannot reproduce The bug cannot be reproduced label Dec 9, 2023
@sapphi-red
Copy link
Member

I wasn't able to reproduce. I ran vite build and vite preview and accessed with Chrome 84. It ran without any errors.
image

@alexookah
Copy link
Author

You are right! it works with vite_preview.
Actually I come from vite_rails where they also support vite_legacy but probably it's not the same outcome.
In a Vue project it works correctly but with rails it's different vite legacy gets used with some html tag.

Created an example repo with vite_rails
https://github.com/alexookah/rails_example
Added a simple test console.log with replaceAll
https://github.com/alexookah/rails_example/blob/master/app/frontend/entrypoints/example_import.js
Screenshot 2023-12-09 at 18 52 00

I think the issue is on ruby rails side.
Created also an issue in vite_ruby repo.

@bluwy
Copy link
Member

bluwy commented Dec 11, 2023

I'll close this for now as it seems to be an integration issue with vite_ruby. @vitejs/plugin-legacy might not always work with frameworks as different frameworks may bundle things differently.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cannot reproduce The bug cannot be reproduced pending triage
Projects
None yet
Development

No branches or pull requests

3 participants