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

[BUG] Vue SFC compilation breaking during SSR due to Vite internal stripLiteral function #11913

Closed
7 tasks done
AaronBeaudoin opened this issue Feb 2, 2023 · 2 comments · Fixed by #12044
Closed
7 tasks done
Labels
bug: upstream Bug in a dependency of Vite

Comments

@AaronBeaudoin
Copy link

Describe the bug

Suppose I have a simple App.vue file like this:

<script>
const getTestData = async () => {
  const filename = "message";
  console.log(await import(`./data/something/${filename}.json`));
  console.log(await import(`./data/whatever/${filename}.json`));
};

getTestData();
export default {};
</script>

<template>
  <div class="whatever">
    {{ new Date() }}
  </div>
</template>

As you can I see, I dynamically import two .json files, which I might do in the real world to get data. When I run my project, I get the following error:

/App.vue:8
  console.log(await __vite_ssr_import_0__.default((__vite_ssr_import_meta__.glob("./data/whatever/*.json")), `./data/whatever/${filename}.json`));
                                                                            ^

TypeError: __vite_ssr_import_meta__.glob is not a function
    at getTestData (/App.vue:8:77)

The error can be avoided by either:

  1. Removing the class="whatever" attribute.
  2. Removing one of the dynamic imports.

The reason for this is because the cause of the issue is the stripLiteral function used internally by Vite. For a more detailed explanation, please read the README of the minimal reproduction repository.

Reproduction

https://github.com/AaronBeaudoin/vite-ssr-issue-vue-sfc-dynamic-import

Steps to reproduce

Please see the minimal reproduction repository for reproduction steps and a detailed explanation.

System Info

System:
    OS: macOS 12.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 74.63 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.19.0 - ~/.volta/tools/image/node/16.19.0/bin/node
    npm: 8.19.3 - ~/.volta/tools/image/node/16.19.0/bin/npm
  Browsers:
    Chrome: 109.0.5414.119
    Safari: 15.6
  npmPackages:
    @vitejs/plugin-vue: ^4.0.0 => 4.0.0 
    vite: ^4.0.4 => 4.0.4

Used Package Manager

npm

Logs

Click to expand!
/App.vue:8
  console.log(await __vite_ssr_import_0__.default((__vite_ssr_import_meta__.glob("./data/whatever/*.json")), `./data/whatever/${filename}.json`));
                                                                            ^

TypeError: __vite_ssr_import_meta__.glob is not a function
    at getTestData (/App.vue:8:77)

Validations

@AaronBeaudoin AaronBeaudoin changed the title [BUG] stripLiteral causes Vue SFC compilation to break during SSR [BUG] Vue SFC compilation breaking during SSR due to internal stripLiteral function Feb 2, 2023
@AaronBeaudoin AaronBeaudoin changed the title [BUG] Vue SFC compilation breaking during SSR due to internal stripLiteral function [BUG] Vue SFC compilation breaking during SSR due to Vite internal stripLiteral function Feb 2, 2023
@AaronBeaudoin
Copy link
Author

AaronBeaudoin commented Feb 3, 2023

A fix has been released for the strip-literal dependency including the relevant code. Is getting the fix in Vite as simple now as updating all the package.json files in the Vite repo that use the package?

@bluwy
Copy link
Member

bluwy commented Feb 6, 2023

Yup, we usually have weekly dependency updates so the new version should be picked up soon.

@bluwy bluwy added bug: upstream Bug in a dependency of Vite and removed pending triage labels Feb 6, 2023
@sapphi-red sapphi-red linked a pull request Feb 13, 2023 that will close this issue
1 task
@github-actions github-actions bot locked and limited conversation to collaborators Feb 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants