Skip to content

build.target = 'es2019' together with base = './' results in import.meta still present in output js #9596

@derMart

Description

@derMart

Describe the bug

According to the docs https://main.vitejs.dev/config/build-options.html#build-target a valid esbuild target could be given to the build.target option. According to https://esbuild.github.io/content-types/#javascript 'es2019' build target should result in import.meta being transformed. This works as long as the base option is an absolute path, as soon as this is a relative path import.meta is still present in the js file generated by npm run build.
See https://github.com/derMart/example_vite_es2019/blob/0a3a35c00f15b84466e1bdd8be1e5eb1ce7b49ce/dist/assets/index.355a229a.js#L4649
and the used config https://github.com/derMart/example_vite_es2019/blob/0a3a35c00f15b84466e1bdd8be1e5eb1ce7b49ce/vite.config.ts
When changing to base: '/' the resulting js will not contain import.meta anymore

Reproduction

https://github.com/derMart/example_vite_es2019

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 9.22 GB / 15.33 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
  Browsers:
    Chrome: 96.0.4664.45
    Chromium: 104.0.5112.79
    Firefox: 103.0.1
  npmPackages:
    @vitejs/plugin-vue: ^3.0.0 => 3.0.1 
    vite: ^3.0.0 => 3.0.4

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions