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

The code after packing has a syntax error: let default; #26

Closed
Rem486 opened this issue Mar 9, 2023 · 2 comments
Closed

The code after packing has a syntax error: let default; #26

Rem486 opened this issue Mar 9, 2023 · 2 comments

Comments

@Rem486
Copy link

Rem486 commented Mar 9, 2023

Hello, we found the code after packing has a syntax error, plz help check this.

Our vue component needs import jquery when it was undefine.

// Component.vue

<script>
import $ from '@/jQueryPlugin';

console.log($);
</script>

// @/jQueryPlugin/index.js

let jQuery;
if (typeof window !== 'undefined') {
  if (!window.$) {
    const jquery = await import('jquery');
    window.$ = jquery.default || jquery;
  }
  jQuery = window.$;
}

export default jQuery;

// component.js

import Component from './Component.vue';

Component.install = app => {
  app.component('VComponent', Component);
};

export default Component;

The code after packing is as follows:
image

@Menci
Copy link
Owner

Menci commented May 20, 2023

Can't reproduce. Please provide more details or upload a full project for me to diagnosis.

 Menci  Mencis-MacBook  ~  vite-tla-bug  (っ・ω・)っ ls -lah src
total 12K
drwxr-xr-x  6 Menci staff 192 May 20 13:10 .
drwxr-xr-x 13 Menci staff 416 May 20 13:10 ..
-rw-r--r--  1 Menci staff  68 May 20 13:05 Component.vue
-rw-r--r--  1 Menci staff 144 May 20 13:05 component.js
drwxr-xr-x  3 Menci staff  96 May 20 13:04 jQueryPlugin
-rw-r--r--  1 Menci staff  95 May 20 13:10 main.js
 Menci  Mencis-MacBook  ~  vite-tla-bug  (っ・ω・)っ bat src/*.* src/jQueryPlugin/*
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: src/Component.vue
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ <script>
   2   │ import $ from './jQueryPlugin';
   3   │
   4   │ console.log($);
   5   │ </script>
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: src/component.js
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ import Component from './Component.vue';
   2   │
   3   │ Component.install = app => {
   4   │   app.component('VComponent', Component);
   5   │ };
   6   │
   7   │ export default Component;
   8   │
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: src/main.js
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ import { createApp } from 'vue'
   2   │ import App from './component.js'
   3   │
   4   │ createApp(App).mount('#app')
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: src/jQueryPlugin/index.js
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ let jQuery;
   2   │ if (typeof window !== 'undefined') {
   3   │   if (!window.$) {
   4   │     const jquery = await import('jquery');
   5   │     window.$ = jquery.default || jquery;
   6   │   }
   7   │   jQuery = window.$;
   8   │ }
   9   │
  10   │ export default jQuery;
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 Menci  Mencis-MacBook  ~  vite-tla-bug  (っ・ω・)っ yarn build
yarn run v1.22.19
$ vite build
vite v4.3.8 building for production...
✓ 15 modules transformed.
Generated an empty chunk: "vue.runtime.esm-bundler.js".
dist/index.html                                        1.23 kB │ gzip:  0.43 kB
dist/assets/vue.runtime.esm-bundler.js-4ed993c7.js     0.00 kB │ gzip:  0.02 kB
dist/assets/jquery.js_commonjs-module-1b758001.js      0.05 kB │ gzip:  0.06 kB
dist/assets/Component.vue-09e66ff7.js                  0.27 kB │ gzip:  0.20 kB
dist/assets/component.js-1f9c572f.js                   0.30 kB │ gzip:  0.21 kB
dist/assets/_commonjsHelpers.js-7d1333e8.js            0.40 kB │ gzip:  0.24 kB
dist/assets/main.js-f71a5ec9.js                        0.44 kB │ gzip:  0.25 kB
dist/assets/index.js-febe0c71.js                       0.53 kB │ gzip:  0.33 kB
dist/assets/modulepreload-polyfill-ccc30ec3.js         1.54 kB │ gzip:  0.57 kB
dist/assets/preload-helper-8dea4d1a.js                 2.21 kB │ gzip:  0.98 kB
dist/assets/shared.esm-bundler.js-1aa6b1c4.js          5.39 kB │ gzip:  1.92 kB
dist/assets/runtime-dom.esm-bundler.js-ee3755c6.js    11.21 kB │ gzip:  3.46 kB
dist/assets/reactivity.esm-bundler.js-ed8f461d.js     24.42 kB │ gzip:  5.48 kB
dist/assets/runtime-core.esm-bundler.js-89cea446.js  106.82 kB │ gzip: 24.56 kB
dist/assets/jquery.js-be7cfa7e.js                    293.14 kB │ gzip: 84.59 kB
✓ built in 567ms
✨  Done in 1.01s.
 Menci  Mencis-MacBook  ~  vite-tla-bug  (っ・ω・)っ grep -r 'let default' dist
 Menci  Mencis-MacBook  ~  vite-tla-bug  ERROR  (。•́︿•̀。) 

@Menci
Copy link
Owner

Menci commented Dec 10, 2023

Closing since no response.

@Menci Menci closed this as completed Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants