Skip to content

Vite not compiling vue SFCs without literal vue/compiler-sfc #6234

@sebwas

Description

@sebwas

Describe the bug

When vue 3 is aliased, vite does not seem to be able to find the compiler-sfc package, even if it is explicitly installed (@vue/compiler-sfc).

From some brief dive into the code, the problem seems to be in plugin-vue/src/compiler.ts, where when trying to resolve the package, the @ symbol is not being considered, whereas previously it was.

The error message produced suggests that installing the package will solve the problem, so either the error message needs to be adjusted, or the problem needs to be solved at the root (I suggest including trying to resolve the package with the @ symbol).

Reproduction

Check out

https://stackblitz.com/edit/vitejs-vite-b9ckpd?file=package.json


In the terminal run npm i && npm run dev and you will see the error message.


The only changes I made was to alias vue and include @vue/compiler-sfc as a devDependency.

System Info

Locally:

  System:
    OS: macOS 12.0.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 269.88 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.2.0 - /opt/homebrew/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.1.4 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 96.0.4664.110
    Firefox: 94.0.2
    Safari: 15.1

Stackblitz:

  System:
    OS: Linux undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: Unknown - /bin/jsh
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
  npmPackages:
    @vitejs/plugin-vue: ^2.0.0 => 2.0.1 
    vite: ^2.7.2 => 2.7.6

Used Package Manager

yarn

Logs

error when starting dev server:
Error: Failed to resolve vue/compiler-sfc.
@vitejs/plugin-vue requires vue (>=3.2.13) or @vue/compiler-sfc to be present in the dependency tree.
    at resolveCompiler (/home/projects/vitejs-vite-b9ckpd/node_modules/@vitejs/plugin-vue/dist/index.js:4069:11)
    at Object.configResolved (/home/projects/vitejs-vite-b9ckpd/node_modules/@vitejs/plugin-vue/dist/index.js:4768:39)
    at eval (/home/projects/vitejs-vite-b9ckpd/node_modules/vite/dist/node/chunks/dep-fcec4469.js:82486:127)
    at Array.map (<anonymous>)
    at resolveConfig (/home/projects/vitejs-vite-b9ckpd/node_modules/vite/dist/node/chunks/dep-fcec4469.js:82486:35)
    at async createServer (/home/projects/vitejs-vite-b9ckpd/node_modules/vite/dist/node/chunks/dep-fcec4469.js:67991:20)
    at async CAC.eval (/home/projects/vitejs-vite-b9ckpd/node_modules/vite/dist/node/cli.js:688:24)

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