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

page use vant and @vitejs/plugin-legacy plugin build. #4358

Closed
4 of 6 tasks
hxdyj opened this issue Jul 23, 2021 · 12 comments
Closed
4 of 6 tasks

page use vant and @vitejs/plugin-legacy plugin build. #4358

hxdyj opened this issue Jul 23, 2021 · 12 comments

Comments

@hxdyj
Copy link

hxdyj commented Jul 23, 2021

Describe the bug

page use vant lib and @vitejs/plugin-legacy plugin build. run in chrome58 get Error SystemJS https://git.io/JvFET#3.
but page only use my component, it will be normal.
image
image

dist/assets not has file ./index-legacy.62d61901.js

Reproduction

https://github.com/hxdyj/vite-bug-legacy

System Info

System:
    OS: Linux 4.4 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (12) x64 AMD Ryzen 5 PRO 4650U with Radeon Graphics
    Memory: 2.58 GB / 15.23 GB
    Container: Yes
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 15.11.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.6.0 - /usr/local/bin/npm
  npmPackages:
    @vitejs/plugin-vue: ^1.2.5 => 1.2.5 
    vite: ^2.4.3 => 2.4.3

Used Package Manager

yarn

Logs

No response

Validations

@hxdyj
Copy link
Author

hxdyj commented Jul 23, 2021

@nulladdict I guess this is plugin @vitejs/plugin-legacy bug.

@gaoxianglyx
Copy link

same error !!!

@hxdyj
Copy link
Author

hxdyj commented Aug 12, 2021

same error !!!

I find the way to build success,
But need modify plugin source code.

@RoxanneCIA
Copy link

same error !!!

I find the way to build success,
But need modify plugin source code.

how to fix it?

@hxdyj
Copy link
Author

hxdyj commented Aug 26, 2021

index 44d1bbc..d626fdc 100644
--- a/node_modules/@vitejs/plugin-legacy/index.js
+++ b/node_modules/@vitejs/plugin-legacy/index.js
@@ -40,6 +40,7 @@ function viteLegacyPlugin(options = {}) {
   const facadeToModernPolyfillMap = new Map()
   const modernPolyfills = new Set()
   const legacyPolyfills = new Set()
+  let nullFacadeMap = {}
 
   if (Array.isArray(options.modernPolyfills)) {
     options.modernPolyfills.forEach((i) => {
@@ -93,12 +94,18 @@ function viteLegacyPlugin(options = {}) {
       if (config.build.minify === 'esbuild') {
         throw new Error(
           `Can't use esbuild as the minifier when targeting legacy browsers ` +
-            `because esbuild minification is not legacy safe.`
+          `because esbuild minification is not legacy safe.`
         )
       }
     },
 
     async generateBundle(opts, bundle) {
+      for (const name in bundle) {
+        let chunk = bundle[name]
+        if (chunk.type === 'chunk' && !chunk.facadeModuleId) {
+          nullFacadeMap[chunk.fileName] = chunk
+        }
+      }
       if (!isLegacyBundle(bundle, opts)) {
         if (!modernPolyfills.size) {
           return
@@ -399,6 +406,7 @@ function viteLegacyPlugin(options = {}) {
     },
 
     generateBundle(opts, bundle) {
+      Object.assign(bundle, nullFacadeMap)
       if (isLegacyBundle(bundle, opts)) {
         // avoid emitting duplicate assets
         for (const name in bundle) {
@@ -434,7 +442,7 @@ function viteLegacyPlugin(options = {}) {
       if (envInjectionFailed) {
         config.logger.warn(
           `[@vitejs/plugin-legacy] import.meta.env.LEGACY was not injected due ` +
-            `to incompatible vite version (requires vite@^2.0.0-beta.69).`
+          `to incompatible vite version (requires vite@^2.0.0-beta.69).`
         )
       }
     }

image
modify node_modules plugin index.js

@Shinigami92
Copy link
Member

@hxdyj Is there a reason why you didn't propose a PR?

@hxdyj
Copy link
Author

hxdyj commented Aug 26, 2021

@hxdyj Is there a reason why you didn't propose a PR?

I'am not very familiar with rollup, just fix it, but my way are not good.

hxdyj added a commit to hxdyj/vite that referenced this issue Aug 30, 2021
fix: some file are not generated while using @vitejs/plugin-legacy (fix vitejs#4358).
@aladdin-add
Copy link

same issue with latest vite and legacy-plugin.

@alvc666
Copy link

alvc666 commented Oct 20, 2021

index 44d1bbc..d626fdc 100644
--- a/node_modules/@vitejs/plugin-legacy/index.js
+++ b/node_modules/@vitejs/plugin-legacy/index.js
@@ -40,6 +40,7 @@ function viteLegacyPlugin(options = {}) {
   const facadeToModernPolyfillMap = new Map()
   const modernPolyfills = new Set()
   const legacyPolyfills = new Set()
+  let nullFacadeMap = {}
 
   if (Array.isArray(options.modernPolyfills)) {
     options.modernPolyfills.forEach((i) => {
@@ -93,12 +94,18 @@ function viteLegacyPlugin(options = {}) {
       if (config.build.minify === 'esbuild') {
         throw new Error(
           `Can't use esbuild as the minifier when targeting legacy browsers ` +
-            `because esbuild minification is not legacy safe.`
+          `because esbuild minification is not legacy safe.`
         )
       }
     },
 
     async generateBundle(opts, bundle) {
+      for (const name in bundle) {
+        let chunk = bundle[name]
+        if (chunk.type === 'chunk' && !chunk.facadeModuleId) {
+          nullFacadeMap[chunk.fileName] = chunk
+        }
+      }
       if (!isLegacyBundle(bundle, opts)) {
         if (!modernPolyfills.size) {
           return
@@ -399,6 +406,7 @@ function viteLegacyPlugin(options = {}) {
     },
 
     generateBundle(opts, bundle) {
+      Object.assign(bundle, nullFacadeMap)
       if (isLegacyBundle(bundle, opts)) {
         // avoid emitting duplicate assets
         for (const name in bundle) {
@@ -434,7 +442,7 @@ function viteLegacyPlugin(options = {}) {
       if (envInjectionFailed) {
         config.logger.warn(
           `[@vitejs/plugin-legacy] import.meta.env.LEGACY was not injected due ` +
-            `to incompatible vite version (requires vite@^2.0.0-beta.69).`
+          `to incompatible vite version (requires vite@^2.0.0-beta.69).`
         )
       }
     }

image modify node_modules plugin index.js

this is work for me, same problem here

vikunja-bot pushed a commit to go-vikunja/frontend that referenced this issue Nov 26, 2021
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@vitejs/plugin-vue](https://github.com/vitejs/vite) | devDependencies | patch | [`1.10.0` -> `1.10.1`](https://renovatebot.com/diffs/npm/@vitejs%2fplugin-vue/1.10.0/1.10.1) |

---

### Release Notes

<details>
<summary>vitejs/vite</summary>

### [`v1.10.1`](https://github.com/vitejs/vite/blob/master/packages/plugin-vue/CHANGELOG.md#&#8203;1101-httpsgithubcomvitejsvitecompareplugin-vue1100plugin-vue1101-2021-11-26)

##### Bug Fixes

-   **plugin-vue:** fix hmr issue in vuejs/vue-next[#&#8203;4358](vitejs/vite#4358) ([709e4b0](vitejs/vite@709e4b0))

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/1091
Co-authored-by: renovate <renovatebot@kolaente.de>
Co-committed-by: renovate <renovatebot@kolaente.de>
@jessechengzhu
Copy link

I had the same problem before,and i tried use VueRouter without dynamic import() then solved it.
Now when I upgrade some dependencies related to vite, the problem is solved automatically, and I can't find the reason😂

@bluwy
Copy link
Member

bluwy commented Mar 13, 2022

Hi @hxdyj. I tested the repro locally and this seems to be fixed now. I dont see any files missing after upgrading Vite to 2.8.6 and plugin-legacy to 1.7.1. Can you confirm if this is fixed for you?

@hxdyj
Copy link
Author

hxdyj commented Mar 14, 2022

Hi @hxdyj. I tested the repro locally and this seems to be fixed now. I dont see any files missing after upgrading Vite to 2.8.6 and plugin-legacy to 1.7.1. Can you confirm if this is fixed for you?

already fixed. Thank you!!

@hxdyj hxdyj closed this as completed Mar 14, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants