vuejs / vuepress

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

@vuepress/plugin-search: Uncaught (in promise) Error: useRouteLocale() is called without provider. #3040

Open jchalex opened 2 years ago

jchalex commented 2 years ago

Bug report

Steps to reproduce

module.exports = {
...
plugins: [
    backToTopPlugin(),
    mediumZoomPlugin({}),
    nprogressPlugin(),
    searchPlugin({}),
  ],
  ...
};

And the whole page is empty, which can not loading correct.

What is expected?

Expecting a search box in the navigation, page loading correct.

What is actually happening?

image image

Other relevant information

"devDependencies": {
    "@vuepress/bundler-vite": "^2.0.0-beta.41",
    "@vuepress/plugin-back-to-top": "^2.0.0-beta.41",
    "@vuepress/plugin-docsearch": "^2.0.0-beta.41",
    "@vuepress/plugin-medium-zoom": "^2.0.0-beta.41",
    "@vuepress/plugin-nprogress": "^2.0.0-beta.41",
    "@vuepress/plugin-register-components": "^2.0.0-beta.43",
    "@vuepress/plugin-search": "^2.0.0-beta.43",
    "@vuepress/theme-default": "^2.0.0-beta.41",
    "vuepress": "^2.0.0-beta.41"
  }
System:
    OS: macOS 11.4
    CPU: (8) x64 Apple M1
    Memory: 22.80 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 8.4.1 - /usr/local/bin/npm
  Utilities:
    Git: 2.30.1 - /usr/bin/git
  Browsers:
    Chrome: 101.0.4951.54
    Edge: Not Found
    Firefox: 92.0
    Safari: 14.1.1
  npmPackages:
    @vuepress/bundler-vite: ^2.0.0-beta.41 => 2.0.0-beta.41 
    @vuepress/bundler-webpack: Not Found
    @vuepress/cli:  2.0.0-beta.41 
    @vuepress/client:  2.0.0-beta.41 (2.0.0-beta.43)
    @vuepress/core:  2.0.0-beta.41 (2.0.0-beta.43)
    @vuepress/markdown:  2.0.0-beta.41 (2.0.0-beta.43)
    @vuepress/plugin-active-header-links:  2.0.0-beta.41 
    @vuepress/plugin-back-to-top: ^2.0.0-beta.41 => 2.0.0-beta.41 
    @vuepress/plugin-container:  2.0.0-beta.41 
    @vuepress/plugin-docsearch: ^2.0.0-beta.41 => 2.0.0-beta.41 
    @vuepress/plugin-external-link-icon:  2.0.0-beta.41 
    @vuepress/plugin-git:  2.0.0-beta.41 
    @vuepress/plugin-google-analytics: Not Found
    @vuepress/plugin-medium-zoom: ^2.0.0-beta.41 => 2.0.0-beta.41 
    @vuepress/plugin-nprogress: ^2.0.0-beta.41 => 2.0.0-beta.41 
    @vuepress/plugin-palette:  2.0.0-beta.41 
    @vuepress/plugin-prismjs:  2.0.0-beta.41 
    @vuepress/plugin-pwa: Not Found
    @vuepress/plugin-pwa-popup: Not Found
    @vuepress/plugin-register-components: ^2.0.0-beta.43 => 2.0.0-beta.43 
    @vuepress/plugin-search: ^2.0.0-beta.43 => 2.0.0-beta.43 
    @vuepress/plugin-shiki: Not Found
    @vuepress/plugin-theme-data:  2.0.0-beta.41 
    @vuepress/plugin-toc: Not Found
    @vuepress/shared:  2.0.0-beta.41 (2.0.0-beta.43)
    @vuepress/theme-default: ^2.0.0-beta.41 => 2.0.0-beta.41 
    @vuepress/utils:  2.0.0-beta.41 (2.0.0-beta.43)
    vue:  3.2.33 
    vue-loader: Not Found
    vue-router:  4.0.14 
    vuepress: ^2.0.0-beta.41 => 2.0.0-beta.41 
    vuepress-vite:  2.0.0-beta.41 
    vuepress-webpack: Not Found
boakenfull commented 2 years ago

I have the same problem here - with 2.0.0-beta.45

straumat commented 2 years ago

Same here with ^2.0.0-beta.46

icodea commented 2 years ago

Same here with ^2.0.0-beta.46

pnpm add vuepress@next--> devDependencies:

mMuyLw

icodea commented 2 years ago

i solve it in my project.

@vuepress/client 2.0.0-beta.46-->@vuepress/client 2.0.0-beta.45 .

❯ pnpm add -D @vuepress/client@2.0.0-beta.45
Packages: +2 -2
++--
Progress: resolved 659, reused 640, downloaded 0, added 0, done

devDependencies:
- @vuepress/client 2.0.0-beta.46
+ @vuepress/client 2.0.0-beta.45
- vuepress 2.0.0-beta.46
+ vuepress 2.0.0-beta.46

and It works successfully!

litingyes commented 2 years ago

when i development my vuepress-theme, i have the same error with using useRouteLocale in my Vue SFC, whether @vuepress/client 2.0.0-beta.45 or @vuepress/client 2.0.0-beta.46 with vuepress@2.0.0-beta.46

icodea commented 2 years ago

Such errors are usually caused by incorrectly containing multiple versions of @vue/xxx, @vuepress/xxx, vue or vue-router in the project.Make sure you are using the latest vuepress and vuepress-plugins and theme versions

15Uj0k

catlair commented 2 years ago

使用 @vuepress/plugin-docsearch@next 遇到同样的问题。

yarn upgrade-interactive makes it work.

zwsnail commented 1 year ago
const { searchPlugin } = require('@vuepress/plugin-search')

module.exports = {
  plugins: [
    searchPlugin({
      // options
    }),
  ],
}

when it shows an error, just run 'npm update' it works for me.

WUTONK commented 1 year ago

I think the problem is that the vuepress version is incompatible with searchPlugin.

image ts(6133)&ts(2307)

image

You need to install the same version of searchPlugin as vuepress to run normally.

And check whether there is such a statement. For me, it is generated automatically when I install it automatically, which will lead to incorrect mapping of pnpm to search plugin

image
"pnpm": "link:@vuepress/plugin-search"

The following code can be referred to:

Installation command pnpm add -D @vuepress/plugin-search@2.0.0-beta.43

config.ts

plugins: [
    // @ts-ignore
    localeRedirectPlugin(),
    backToTopPlugin(),
    nprogressPlugin(),
    mediumZoomPlugin({
      delay: 50 //切换路由后开始生效的延迟时间
    }),
    searchPlugin({

      maxSuggestions : 7,
      //将首页排除出可搜索名单
      isSearchable: (page) => page.path !== '/',

      locales: {
        '/en/': {
          placeholder: 'Search',
        },
        '/zh/': {
          placeholder: '搜索',
        },
        '/jp/': {
          placeholder: '検索',
        },
      },
    }),
  ],

package.json

  `"devDependencies": {
    "@kecrily/eslint-config": "^0.1.3",
    "@vuepress/client": "^2.0.0-beta.43",
    "@vuepress/plugin-search": "2.0.0-beta.43",
    "eslint": "^8.15.0",
    "postcss": "^8.4.13",
    "typescript": "^4.6.4",
    "vue": "^3.2.33",
    "vuepress": "2.0.0-beta.43",
    "vuepress-plugin-locale-redirect": "^1.0.1"
  },