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

when i build the vue3 project, i got a output file name like [component].vue_vue_type_script_setup_true_lang.[hash].js #19

Open
7 tasks done
JiatLn opened this issue Jul 19, 2022 · 36 comments
Labels
enhancement New feature or request has workaround p2-nice-to-have 🍰 Not breaking anything but nice to have (priority)

Comments

@JiatLn
Copy link

JiatLn commented Jul 19, 2022

Describe the bug

when i npm run build, i got a output file name like [component].vue_vue_type_script_setup_true_lang.[hash].js

image

Reproduction

https://github.com/JiatLn/vite-build-demo.git

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (4) x64 Intel(R) Core(TM) i3-6100 CPU @ 3.70GHz
    Memory: 1.36 GB / 7.88 GB
  Binaries:
    Node: 14.19.0 - E:\software\nodejs\node.EXE
    Yarn: 1.22.18 - E:\software\nodejs\yarn.CMD
    npm: 6.14.16 - E:\software\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (103.0.1264.62)
    Internet Explorer: 11.0.19041.1202

Used Package Manager

yarn

Logs

No response

Validations

@sapphi-red
Copy link
Member

What is the problem here?

@ydcjeff
Copy link

ydcjeff commented Jul 30, 2022

I think the problem is the weird output (comp.vue_vue_type_script_setup_true_lang.[hash].js) instead of [name].[hash].js.

@sapphi-red
Copy link
Member

The name is generated by rollup from id(comp.vue?vue&type=script&setup=true&lang.js).
We could treat vue files specially and replace the filename in generateBundle hook. But I don't think this causes any problem.

@bluwy bluwy added enhancement New feature or request p2-nice-to-have 🍰 Not breaking anything but nice to have (priority) and removed pending triage labels Aug 16, 2022
@hrishikesh-k
Copy link

hrishikesh-k commented Aug 22, 2022

It's probably not a problem, except the cause is unknown. I did not have a problem in any of my other Vite 3 + Vue 3 projects. I haven't made many, but not sure what's happening here. Here's how my chunks folder looks:

image

My Vite config:

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
  build: {
    rollupOptions: {
      output: {
        assetFileNames: 'assets/[name].[ext]',
        chunkFileNames: 'chunks/[name].js',
        entryFileNames: 'entries/[name].js'
      }
    },
    sourcemap: true,
    target: 'esnext'
  }
})

Note that, badge is the only file from my components folder that's ending up like that:

image

while all the other chunks are from my pages directory:

image

I know this is not really useful without me actually providing a reproduction (as I've said, this doesn't always happen), but providing a reproduction is most likely going to be tough. If someone has some pointers on what to check (try to add/edit) to avoid this, that would be great!

Note that, the badge component is nothing fancy. It's a super simple component which is using defineProps, computed and is one of my smallest components. button for example is a bit complex than that - with various states and props, it goes about 200 lines. So, I don't think "complexity" of the component is an issue (not sure if it ever was), but that's my only guess.

@JiatLn
Copy link
Author

JiatLn commented Aug 23, 2022

It's probably not a problem, except the cause is unknown. I did not have a problem in any of my other Vite 3 + Vue 3 projects. I haven't made many, but not sure what's happening here. Here's how my chunks folder looks:

image

My Vite config:

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
  build: {
    rollupOptions: {
      output: {
        assetFileNames: 'assets/[name].[ext]',
        chunkFileNames: 'chunks/[name].js',
        entryFileNames: 'entries/[name].js'
      }
    },
    sourcemap: true,
    target: 'esnext'
  }
})

Note that, badge is the only file from my components folder that's ending up like that:

image

while all the other chunks are from my pages directory:

image

I know this is not really useful without me actually providing a reproduction (as I've said, this doesn't always happen), but providing a reproduction is most likely going to be tough. If someone has some pointers on what to check (try to add/edit) to avoid this, that would be great!

Note that, the badge component is nothing fancy. It's a super simple component which is using defineProps, computed and is one of my smallest components. button for example is a bit complex than that - with various states and props, it goes about 200 lines. So, I don't think "complexity" of the component is an issue (not sure if it ever was), but that's my only guess.

I have a guess that it will happen when the component had use to many times.

@hrishikesh-k
Copy link

Thank you for your message!

I have a guess that it will happen when the component had use to many times.

I don't think it's being used too many times, but even if that's the case, it still doesn't explain the weird name that component is getting while others are working as expected.

@BigFrontEnd-China
Copy link

BigFrontEnd-China commented Sep 8, 2022

I have the same problem!
image
image

// package.json
{
  "name": "demo-components",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc --noEmit && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "vue": "^3.2.37"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^3.1.0",
    "typescript": "^4.6.4",
    "vite": "^3.1.0",
    "vue-tsc": "^0.40.4"
  }
}
// vite.config.ts
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    lib: {
      entry: "./src/components/index.ts",
      formats: ["cjs"],
      name: "components",
    },
    rollupOptions: {
      external: ["vue"],
      output: [
        {
          dir: "dist/components",
          format: "cjs",
          entryFileNames: "[name].js",
          preserveModules: true,
          preserveModulesRoot: "components",
        },
      ],
    },
  },
  plugins: [vue()],
});

@robokozo
Copy link

robokozo commented Sep 28, 2022

I'm also seeing the same thing:

...
dist/assets/dates.32565151.js  
dist/assets/ConfirmationButton.vue_vue_type_script_setup_true_lang.db3c1ab5.js
dist/assets/SubtleSortToggleButton.vue_vue_type_script_setup_true_lang.d7615288.js
dist/assets/index.350ee0b4.css
...

Also FWIW.. those components also seem to be MASSIVE compared to what they actually are. That SubtleSortToggleButton is 146.95 KiB. It's a <button> with some css toggling

When I inspect the minified js it also seems to include a lot of stuff that I wasn't expecting.

@JiatLn 's affected FillBlankTextarea is also significantly larger than the others

@jonaskuske
Copy link

@robokozo are you using any images, fonts, other kinds of assets? All assets are inlined into the JS/CSS files if you build in lib mode, so the generated JS/CSS files can get huge.

@robokozo
Copy link

@jonaskuske its a normal vue app. I can show the details tomorrow but the file is a relatively simple. It's a button that uses different classes based on a Boolean. I believe it only has 1 dependency on a file with interface definitions.

@lingdu1234
Copy link

2022-10-18 184452
i have the same problem ,not all the file,and not found any reason

@haoqunjiang haoqunjiang transferred this issue from vitejs/vite Dec 3, 2022
@hrishikesh-k
Copy link

Still seems to happen with Vite 4. It's always the same files that have this problem. So, there must be some kind of a consistency, not sure what though.

@emhamzahazeen
Copy link

Have the same issue. I've noticed in my case that if the the component is traversed multiple times by the bundler then it produces one file with correct name which in turn references to the weird name file.

@woyehenni
Copy link

I have the same problem!
I used the plugin 'vite-plugin-multi-pages' to support multi page application.
The currently generated assets are

.
├── assets
│   ├── css
│   │   ├── [componentA].css
│   │   ├── [componentB].css
│   │   ├── main.css
│   │   ├── page1
│   │   │   └── index.css
│   │   ├── page2
│   │   │   └── index.css
│   │   └── page3
│   │       └── index.css
├── favicon.ico
├── js
│   ├── common
│   │   ├── [componentA].vue_vue_type_script_setup_true_lang.js
│   │   ├── [componentB].vue_vue_type_script_setup_true_lang.js
│   │   └── main.js
│   ├── page1.js
│   ├── page2.js
│   └── page3.js
├── page1.html
├── page2.html
└── page3.html

what i expect is

.
├── assets
│   ├── css
│   │   ├── main.css
│   │   ├── page1
│   │   │   └── index.css
│   │   ├── page2
│   │   │   └── index.css
│   │   └── page3
│   │       └── index.css
├── favicon.ico
├── js
│   ├── common
│   │   └── main.js
│   ├── page1.js
│   ├── page2.js
│   └── page3.js
├── page1.html
├── page2.html
└── page3.html

The code in [componentA].vue_vue_type_script_setup_true_lang.js is a common code and has nothing to do with [componentA].

The css in [componentA].css is a common css and has nothing to do with [componentA].

@wrufeger
Copy link

for me the files with that cryptic name showed up after using import statements in async loaded components

@dflock

This comment was marked as resolved.

@dflock

This comment was marked as resolved.

@dflock

This comment was marked as resolved.

@dflock

This comment was marked as resolved.

@chris-upmind
Copy link

I also have this same issue :(. Seems to be for shared components being imported into more than one asynchronously loaded/defined components.

@GideonRoose

This comment was marked as resolved.

@sapphi-red
Copy link
Member

@dflock @GideonRoose I created a new issue for that problem as I think it is slightly different and should have a higher priority than this issue: #169

@jfrs
Copy link

jfrs commented May 12, 2023

I'm wondering if the other template parameters could be ignored just like generic? It doesn't seem to break anything for me but it's a little bit annoying.

@dflock

This comment was marked as resolved.

@sapphi-red

This comment was marked as resolved.

@dflock

This comment was marked as resolved.

@jiikoosol
Copy link

I had the same problem and can confirm that it is related to component imports (what @chris-upmind mentioned above). I'm asynchronously importing several components in a file and I had one of the components also imported inside those async components. Whenever I ran build phase the component got .vue_vue_type_script_setup_true_lang.[hash].js appended to it's filename. After I removed the double-imported component from the async import list everything was working as intended.

@thexeos
Copy link

thexeos commented Jun 2, 2023

Since there is no actual code output or bundling issue in Vite or this plugin and the problem is purely aesthetic, you can avoid names like that by using this simple function in your Vite config (compatible with Vite 4):

rollupOptions: {
  output: {
    chunkFileNames: (assetInfo) => {
      if (assetInfo.name?.endsWith('.vue_vue_type_style_index_0_lang')) {
        return `assets/${assetInfo.name.slice(0, -32)}-[hash:8].js`
      } else if (assetInfo.name?.endsWith('.vue_vue_type_script_setup_true_lang')) {
        return `assets/${assetInfo.name.slice(0, -36)}-[hash:8].js`
      } else {
        return 'assets/[name]-[hash:8].js'
      }
    }
  }
}

This change will only affect the file name - file contents remain the same and, as mentioned above, will include any external libraries that your component and no other component in the application relies on.

@Vector-Green
Copy link

Is there a way without rollup options?
it breaks, for example vite-plugin-compressin

@exidot
Copy link

exidot commented Sep 14, 2023

Now there is still this problem, I wrote a project to reproduce it.
https://github.com/exidot/vitepluginvue-iss19-reproduce

1

2

3

@exidot
Copy link

exidot commented Sep 15, 2023

Now there is still this problem, I wrote a project to reproduce it. https://github.com/exidot/vitepluginvue-iss19-reproduce

1

2

3

Sorry, my conclusion was wrong, and I did not find a pattern in which it occurred !

@litvinenkow
Copy link

litvinenkow commented Dec 24, 2023

i'm having this issue too, it happens when component imported twice or more in project and this genrates too big files importing full css from main component and js

@Shuyinsama
Copy link

Same issue here. It seems to get triggered by something. It did seem to trigger on components that are imported more then once (which is weird in itself since that is the whole idea in a component based project).

For us it also seems to try and import a lot of other components that are not even related to the component. It generates a 51kb file with a lot of imports not even used in the source file.

Could it be an issue with Vue/Async/Suspense and Vite?

@sinchijackal
Copy link

Now there is still this problem, I wrote a project to reproduce it. https://github.com/exidot/vitepluginvue-iss19-reproduce
1
2
3

Sorry, my conclusion was wrong, and I did not find a pattern in which it occurred !

Same problem occurs with vite 5.0. and vue js 3.4.
tested with these packages:

"@types/node": "^18.19.3",
"@vitejs/plugin-vue": "^4.5.2",
"typescript": "~5.3.0",
"vite": "^5.0.10",
"vue-tsc": "^1.8.25"

@babsey
Copy link

babsey commented Apr 12, 2024

Is the issue still on?

My temporary solution is (similar to @thexeos):

chunkFileNames: (assetInfo: { name: string }) => {
    const name = 
        assetInfo.name.endsWith(".vue_vue_type_style_index_0_lang") ||
        assetInfo.name.endsWith(".vue_vue_type_script_setup_true_lang") ? 
        assetInfo.name.split(".")[0] : assetInfo.name;
    return `assets/js/${name}-[hash].js`;
}

@jfrs
Copy link

jfrs commented Aug 1, 2024

Is this definitely a vite-plugin-vue issue or could it a Vite problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request has workaround p2-nice-to-have 🍰 Not breaking anything but nice to have (priority)
Projects
None yet
Development

No branches or pull requests