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

Define array constants in the define configuration will be double length in browser #5150

Closed
7 tasks done
thiled opened this issue Sep 30, 2021 · 4 comments · Fixed by #5155
Closed
7 tasks done

Define array constants in the define configuration will be double length in browser #5150

thiled opened this issue Sep 30, 2021 · 4 comments · Fixed by #5155

Comments

@thiled
Copy link

thiled commented Sep 30, 2021

Describe the bug

see Reproduction below

Reproduction

// vite.config.js

export default defineConfig({
  define: {
      a:[1]
    },
});

// browser console

a 

// output

[1,1]

System Info

System:
    OS: Linux 5.13 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
    Memory: 2.07 GB / 15.53 GB
    Container: Yes
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node
    npm: 6.14.10 - ~/.nvm/versions/node/v14.15.4/bin/npm
  Browsers:
    Chromium: 93.0.4577.63
  npmPackages:
    vite: 2.5.10 => 2.5.10

Used Package Manager

npm

Logs

No response

Validations

@thiled thiled changed the title Define array variables in the define configuration will be double length in browser Define array constants in the define configuration will be double length in browser Sep 30, 2021
@thiled
Copy link
Author

thiled commented Oct 7, 2021

this issue should not be closed, the problem still remains in 2.6.4

@patak-dev patak-dev reopened this Oct 7, 2021
@bluwy
Copy link
Member

bluwy commented Oct 7, 2021

I can't reproduce this, would be helpful if you can share the logs where VIte shows the resolved config, and the vite plugins used.

@thiled
Copy link
Author

thiled commented Oct 8, 2021

sorry for the part of defineConfig.

Reproduction

import path from 'path';
import { defineConfig } from 'vite';
import { createVuePlugin } from 'vite-plugin-vue2';
import { viteExternalsPlugin } from 'vite-plugin-externals';

export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  define: {
    a: [1],
  },
  base: '/',
  plugins: [
    createVuePlugin(),
    viteExternalsPlugin({
      axios: 'axios', // this caused the problem?
    }),
  ],
});

// browser console

a 

// output

[1,1]

@haoqunjiang
Copy link
Member

Bug in vite-plugin-externals. Not in Vite core.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants