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

Regression in plugin-vue 1.8 can't import const enum #5795

Closed
7 tasks done
jods4 opened this issue Nov 22, 2021 · 4 comments
Closed
7 tasks done

Regression in plugin-vue 1.8 can't import const enum #5795

jods4 opened this issue Nov 22, 2021 · 4 comments
Labels
pending triage regression The issue only appears after a new release

Comments

@jods4
Copy link
Contributor

jods4 commented Nov 22, 2021

Describe the bug

My project uses Typescript const enum.
During dev, it goes through esbuild and they are handled like regular enums, no problem.
When building for prod, I have tweaked my vite config to use tsc compiler, so const enums actually work as they should (they're replaced by constants).

This was all fine until plugin-vue version 1.7.0.
After upgrading to 1.8.0 my build fails with an error that says "ImportedEnum is not exported by ModuleThatExportsEnum".

Reproduction

vite.config.js that uses TS to build for prod:

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import ts from "rollup-plugin-typescript2";

export default defineConfig(({ command, mode }) => ({
  plugins: [ vue() ],
  esbuild: command !== "build",
  {
    apply: "build",
    ...ts({ abortOnError: false, check: false }),
  },
}))

All you need now is an exported const enum, e.g. enums.ts:

export const enum E { a = 1, b = 2 }

And a vue file that consumes it, e.g. test.vue:

<template>Hello</template>

<script setup type="ts">
  import { E } from "./enums"

  if (E.a > 0) console.log(":wave:")
</script>

If you run vite build with plugin-vue >= 1.8.0 it will fail.

System Info

System:
    OS: Windows 10 10.0.18363
    CPU: (12) x64 Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz
    Memory: 4.24 GB / 15.79 GB
  Binaries:
    Node: 16.6.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.19.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.18362.1593.0)
    Internet Explorer: 11.0.18362.1766

Used Package Manager

npm

Logs

Error: 'AuditChange' is not exported by Services\user.ts, imported by Modules\Users\Components\user.vue

Validations

@Niputi Niputi added plugin: vue regression The issue only appears after a new release labels Nov 22, 2021
@sapphi-red
Copy link
Member

This is caused by this change.
93d9a2d#diff-50999b66ad3fff48fd315417d4f8c98741da9f85a0fa6bb4ba212cc8f8bac967L271-R267
The same reason with #5044.

@jods4
Copy link
Contributor Author

jods4 commented Apr 19, 2022

@sapphi-red thanks for debugging this! Hopefully that can lead to a fix.
I can confirm this is still an issue in plugin-vue 2.3.1 -- it's an upgrade blocker.

@jods4
Copy link
Contributor Author

jods4 commented Apr 26, 2022

I tested with my project and can confirm @sapphi-red is right, this is the culprit here.
I see what's happening and I'll create a new issue that has a better description of the general problem, rather than its symptoms.

jods4 added a commit to jods4/vite that referenced this issue Apr 26, 2022
Partial revert of 93d9a2d
When building, TS scripts must not be inlined so that loaders (e.g. rollup-plugin-typescript2) are correctly applied.

Fixes vitejs#5044, vitejs#5795, vitejs#7908
@patak-dev
Copy link
Member

Fixed by #7909

@github-actions github-actions bot locked and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pending triage regression The issue only appears after a new release
Projects
None yet
Development

No branches or pull requests

4 participants