usePageHead() is called without provider #103
-
Hi, Vuepress fam! I'm seeing this error I'm using the node API from inside an internal CLI tool which among other things it builds docs using vuepress, the tool is packaged and distributed through NPM. After I publish the package and try running it, It fails with the error. Weirdly when I use {
version: '2.0.0-beta.6',
options: {
base: '/cli/',
lang: 'en-US',
title: 'CLI Documentation',
description: "Documentation for CLI",
head: [],
locales: {},
theme: '@vuepress/default',
themeConfig: { sidebarDepth: 2, sidebar: 'auto' },
bundler: '@vuepress/vite',
bundlerConfig: {},
source: '/Users/**/Work/test-project/docs',
dest: '/Users/**/Work/test-project/docs/.vuepress/dist',
temp: '/Users/**/Work/test-project/docs/.vuepress/.temp',
cache: '/Users/**/Work/test-project/docs/.vuepress/.cache',
public: '/Users/**/Work/test-project/docs/.vuepress/public',
markdown: {},
debug: false,
host: '0.0.0.0',
port: 8080,
open: false,
evergreen: true,
pagePatterns: [ '**/*.md', '!.vuepress', '!node_modules' ],
templateDev: '/Users/**/.nvm/versions/node/v12.18.4/lib/node_modules/cli-package/node_modules/@vuepress/client/templates/index.dev.html',
templateSSR: '/Users/**/.nvm/versions/node/v12.18.4/lib/node_modules/cli-package/node_modules/@vuepress/client/templates/index.ssr.html',
shouldPreload: true,
shouldPrefetch: false
},
dir: {
cache: [Function],
temp: [Function],
source: [Function],
dest: [Function],
client: [Function],
public: [Function]
},
env: {
isProd: false,
isTest: false,
isDev: false,
isDebug: false,
nodeEnv: undefined
},
siteData: {
base: '/cli/',
lang: 'en-US',
title: 'CLI Documentation',
description: "Documentation for CLI",
head: [],
locales: {}
},
markdown: MarkdownIt {
inline: ParserInline { ruler: [Ruler], ruler2: [Ruler] },
block: ParserBlock { ruler: [Ruler] },
core: Core { ruler: [Ruler] },
renderer: Renderer { rules: [Object] },
linkify: LinkifyIt {
__opts__: [Object],
__index__: -1,
__last_index__: -1,
__schema__: '',
__text_cache__: '',
__schemas__: [Object],
__compiled__: [Object],
__tlds__: [Array],
__tlds_replaced__: false,
re: [Object]
},
validateLink: [Function: validateLink],
normalizeLink: [Function: normalizeLink],
normalizeLinkText: [Function: normalizeLinkText],
utils: {
lib: [Object],
assign: [Function: assign],
isString: [Function: isString],
has: [Function: has],
unescapeMd: [Function: unescapeMd],
unescapeAll: [Function: unescapeAll],
isValidEntityCode: [Function: isValidEntityCode],
fromCodePoint: [Function: fromCodePoint],
escapeHtml: [Function: escapeHtml],
arrayReplaceAt: [Function: arrayReplaceAt],
isSpace: [Function: isSpace],
isWhiteSpace: [Function: isWhiteSpace],
isMdAsciiPunct: [Function: isMdAsciiPunct],
isPunctChar: [Function: isPunctChar],
escapeRE: [Function: escapeRE],
normalizeReference: [Function: normalizeReference]
},
helpers: {
parseLinkLabel: [Function: parseLinkLabel],
parseLinkDestination: [Function: parseLinkDestination],
parseLinkTitle: [Function: parseLinkTitle]
},
options: {
html: true,
xhtmlOut: false,
breaks: false,
langPrefix: 'language-',
linkify: false,
typographer: false,
quotes: '“”‘’',
highlight: null,
maxNesting: 100
},
render: [Function]
},
pluginApi: {
plugins: [],
hooks: {
onInitialized: [Object],
onPrepared: [Object],
onWatched: [Object],
onGenerated: [Object],
extendsPageOptions: [Object],
extendsPageData: [Object],
extendsMarkdown: [Object],
clientAppEnhanceFiles: [Object],
clientAppRootComponentFiles: [Object],
clientAppSetupFiles: [Object],
alias: [Object],
define: [Object]
},
registerHooks: [Function]
},
use: [Function: use],
useByConfig: [Function: useByConfig],
init: [Function: init],
prepare: [Function: prepare],
dev: [Function: dev],
build: [Function: build]
} |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 8 replies
-
You'd better provide a reproduce repo. This sounds to be caused by vite's pre-bundling feature. Some packages might be pre-bundled unexpectly. |
Beta Was this translation helpful? Give feedback.
-
I should have added that this happens during the "Rendering pages" stage. It compiles fine.
|
Beta Was this translation helpful? Give feedback.
-
Another piece of info is that when I run the package (cli) inside the project itself it runs with no issues, the problem only happens when I run it on other projects. This is what that method to build the docs looks like: import path from 'path'
import fs from 'fs-extra'
process.env.NODE_ENV = 'production'
const TEMP_LOCATION = path.resolve('.temp')
const buildDocs = async (space: string, docsLoc = 'docs') => {
/**
* Create the temporary directory and copy docs to it
*/
await fs.ensureDir(TEMP_LOCATION)
await fs.copy(`${docsLoc}/.`, TEMP_LOCATION)
/**
* Create and build the app from the docs in the temp directory
*/
const app = createApp({
source: TEMP_LOCATION,
bundler: '@vuepress/vite',
base: `/${space}/`,
title: `${capitalize(space)} Documentation`,
themeConfig: { sidebarDepth: 2, sidebar: 'auto' },
description: `Documentation for ${capitalize(space)} space`
})
await app.init()
await app.prepare()
return app.build()
} |
Beta Was this translation helpful? Give feedback.
-
@meteorlxy I was able to extract the vuepress portion from our cli and create a reproduction repo, could you please take a quick peek at the problem? To reproduce, using node Step 1: Clone repo git clone https://github.com/DanielPe05/vuepress-cli-repro.git Step 2: Change into repo cd vuepress-cli-repro Step 3: Install deps and build the project npm i
npm run build Step 4: Link CLI locally npm link Step 5: Create a target project cd ..
mkdir target-project
cd target-project
mkdir docs
echo '# Hello VuePress' > docs/README.md Step 6: Run linked CLI on target project vuepress-starter run At this point Vuepress will build successfully but during the render stage you should see the following error: ⠋ Rendering pages⠋ Rendering pages /Error: usePageHead() is called without provider.
at usePageHead (/Users/**/Work/target-project/.temp/.vuepress/dist/.server/server.js:83:11)
at useUpdateHead (/Users/**/Work/target-project/.temp/.vuepress/dist/.server/server.js:149:16)
at setup (/Users/**/Work/target-project/.temp/.vuepress/dist/.server/server.js:1016:7)
at callWithErrorHandling (/Users/**/Work/vuepress-starter/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:119:22)
at setupStatefulComponent (/Users/**/Work/vuepress-starter/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:5365:29)
at setupComponent (/Users/**/Work/vuepress-starter/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:5346:11)
at renderComponentVNode (/Users/**/Work/vuepress-starter/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:157:17)
at Object.renderToString (/Users/**/Work/vuepress-starter/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:409:26)
at Object.renderPage (/Users/**/Work/vuepress-starter/node_modules/@vuepress/bundler-vite/lib/build/renderPage.js:22:50)
at async /Users/**/Work/vuepress-starter/node_modules/@vuepress/bundler-vite/lib/build/createBuild.js:48:13
[Vue warn]: Component is missing template or render function.
⠙ Rendering pagesError: usePageHead() is called without provider.
at usePageHead (/Users/**/Work/target-project/.temp/.vuepress/dist/.server/server.js:83:11)
at useUpdateHead (/Users/**/Work/target-project/.temp/.vuepress/dist/.server/server.js:149:16)
at setup (/Users/**/Work/target-project/.temp/.vuepress/dist/.server/server.js:1016:7)
at callWithErrorHandling (/Users/**/Work/vuepress-starter/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:119:22)
at setupStatefulComponent (/Users/**/Work/vuepress-starter/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:5365:29)
at setupComponent (/Users/**/Work/vuepress-starter/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:5346:11)
at renderComponentVNode (/Users/**/Work/vuepress-starter/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:157:17)
at Object.renderToString (/Users/**/Work/vuepress-starter/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:409:26)
at Object.renderPage (/Users/**/Work/vuepress-starter/node_modules/@vuepress/bundler-vite/lib/build/renderPage.js:22:50)
at async /Users/**/Work/vuepress-starter/node_modules/@vuepress/bundler-vite/lib/build/createBuild.js:48:13
[Vue warn]: Component is missing template or render function. However, if you enter the I really appreciate the help and I'm sorry to continue pressing on this issue but I have spent countless hours trying to figure out the root cause of the problem without success. So any insight into this issue is highly appreciated. |
Beta Was this translation helpful? Give feedback.
-
I'm also encountering this error, I'm developing a nx plugin integration with VuePress, which means I'm using programmatic API export from VuePress instead of VuePress CLI, just like: import { VuePressBuildSchema, Res } from '../schema';
import { from, Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { build, allowTs } from 'vuepress';
export const startVuePressBuild = (
schema: VuePressBuildSchema
): Observable<Res> => {
return new Observable((subscriber) => {
allowTs();
from(
build(schema.root, {
config: schema.configPath,
})
).pipe(
tap(() => {
subscriber.next({
success: true,
});
})
);
});
}; And when invoking this, I got same errors above.
|
Beta Was this translation helpful? Give feedback.
-
This seems to still be an issue. I tried using a git submodule in my project to get the latest features because the latest beta is too outdated for me and none of the ways I linked them together appear to work, it always fails with the same error:
This is not the only thing I've tried but one state that doesn't work can be seen here: https://github.com/Joelius300/werewolf-guide/tree/use-vuepress-from-source |
Beta Was this translation helpful? Give feedback.
-
Any progress on this one, is it still existing with latest vuepress, vite, webpack and vue? |
Beta Was this translation helpful? Give feedback.
-
Still seeing this now on |
Beta Was this translation helpful? Give feedback.
-
Is there any solution to this? I'm experiencing this issue with |
Beta Was this translation helpful? Give feedback.
-
maybe it can help
https://vuepress-theme-hope.github.io/v2/faq/common-error.html#usexxx-is-called-without-provider |
Beta Was this translation helpful? Give feedback.
maybe it can help
https://vuepress-theme-hope.github.io/v2/faq/common-error.html#usexxx-is-called-without-provider