vuejs / vuepress

📝 Minimalistic Vue-powered static site generator
https://vuepress.vuejs.org
MIT License
22.59k stars 4.76k forks source link

Cannot build after configured alias vue to vue/dist/vue.esm-bundler.js #3220

Open tzfun opened 5 months ago

tzfun commented 5 months ago

Bug report

After I configured the alias, the build kept reporting errors:

config.js


function _resolve(dir) {
    return path.resolve(__dirname, '../../node_modules', dir)
}

export default defineUserConfig({

    ...

    bundler: viteBundler({
        viteOptions: {
            resolve: {
                alias: {
                    'vue': _resolve('vue/dist/vue.esm-bundler.js')
                }
            }
        }
    })

   ...

})

error stack:

[vite:load-fallback] Could not load E:/Project/<project_name>/doc-vuepress/node_modules/vue/dist/vue.esm-bundler.js/server-renderer (imported by node_modules/.pnpm/@vuepress+theme-default@2.0.0-rc.35_vuepress@2.0.0-rc.13/node_modules/@vuepress/theme-default/lib/client/layouts/NotFound.vue): ENOENT: no such file or directory, open 'E:\Project\<project_name>\doc-vuepress\node_modules\vue\dist\vue.esm-bundler.js\server-renderer'
    at async open (node:internal/fs/promises:641:25)
    at async Object.readFile (node:internal/fs/promises:1254:14)
    at async Object.load (file:///E:/Project/<project_name>/doc-vuepress/node_modules/.pnpm/vite@5.2.13/node_modules/vite/dist/node/chunks/dep-DEPSZ3SS.js:68377:33)
    at async PluginDriver.hookFirstAndGetPlugin (file:///E:/Project/<project_name>/doc-vuepress/node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:19674:28)
    at async file:///E:/Project/<project_name>/doc-vuepress/node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:18845:33
    at async Queue.work (file:///E:/Project/<project_name>/doc-vuepress/node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:19884:32)
ELIFECYCLE Command failed with exit code 1.

Steps to reproduce

What is expected?

Fix or provide a solution.

Other relevant information

My project needs to compile Vue code at runtime, so I need to use vue.esm-bundler.js instead of vue.runtime.esm-bundler.js, so Vue prompted me a warning: [Vue warn]: Component provided template option but runtime compilation is not supported in this build of Vue. Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".

I configured the alias as prompted. When I start in the development environment (pnpm run docs:dev), everything is ok, but when I execute the package (pnpm run docs:build), the above error is reported.

When I remove this alias, the build runs ok, but I can't achieve the effect I want because Vue doesn't have runtime compilation turned on, and a warning is still prompted.

  System:
    OS: Windows 10 10.0.19045
    CPU: (6) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
    Memory: 12.74 GB / 31.94 GB
  Binaries:
    Node: 22.2.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.21 - D:\nodejs\node_global\yarn.CMD
    npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 7.20.0 - ~\AppData\Local\pnpm\pnpm.EXE
    bun: Not Found
  Utilities:
    Git: 2.27.0.
  Browsers:
    Chrome: 125.0.6422.142
    Edge: Chromium (125.0.2535.92)
  npmPackages:
    @vuepress/bundler-vite: ^2.0.0-rc.13 => 2.0.0-rc.13
    @vuepress/bundler-webpack: Not Found
    @vuepress/cli: Not Found
    @vuepress/client: ^2.0.0-rc.2 => 2.0.0-rc.13
    @vuepress/core: Not Found
    @vuepress/markdown: Not Found
    @vuepress/shared: Not Found
    @vuepress/utils: 2.0.0-rc.2 => 2.0.0-rc.2
    vue: ^3.4.0 => 3.4.27
    vue-router: Not Found
    vuepress: ^2.0.0-rc.7 => 2.0.0-rc.13