docsify: docsify-server-renderer error
My code here:
// docs-renderer.js
const fs = require('fs')
const path = require('path')
const docsifyRenderer = require('docsify-server-renderer')
const templatePath = path.resolve(__dirname, '../../docs/index.template.html')
const docsifyConfig = {
basePath: '/src',
// ...
}
const renderer = new docsifyRenderer({
template: fs.readFileSync(templatePath, 'utf-8'),
config: docsifyConfig
})
async function test () {
renderer.renderToString('docs/')
.then(console.log)
.catch(console.log)
}
test()
module.exports = renderer
Then:
TypeError: Cannot read property 'indexOf' of undefined
at AbstractHistory.parse (/Users/zhangshuyao/Sites/git/docs/node_modules/docsify-server-renderer/build.js:349:30)
at Compiler.compile (/Users/zhangshuyao/Sites/git/docs/node_modules/docsify-server-renderer/build.js:553:37)
at Renderer.<anonymous> (/Users/zhangshuyao/Sites/git/docs/node_modules/docsify-server-renderer/build.js:1126:28)
at Generator.next (<anonymous>)
at c (/Users/zhangshuyao/Sites/git/docs/node_modules/docsify-server-renderer/build.js:14:99)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:11)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
There is shotcut of docsify-server-renderer/build.js
// line 553
var curFileName = this$1.router.parse().file;
// line 346-360
AbstractHistory.prototype.parse = function parse (path$$1) {
var query = '';
var queryIndex = path$$1.indexOf('?');
if (queryIndex >= 0) {
query = path$$1.slice(queryIndex + 1);
path$$1 = path$$1.slice(0, queryIndex);
}
return {
path: path$$1,
file: this.getFile(path$$1),
query: parseQuery(query)
}
};
I think maybe there is something wrong with my code or build.js after rollup-build, pls help me to check it.
Best
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 21 (2 by maintainers)
Commits related to this issue
- fix(ssr): AbstractHistory.parse error fix #704 — committed to docsifyjs/docsify by QingWei-Li 5 years ago
- fix(ssr): AbstractHistory.parse error fix #704 — committed to docsifyjs/docsify by QingWei-Li 5 years ago
- fix(ssr): AbstractHistory.parse error fix #704 — committed to docsifyjs/docsify by QingWei-Li 5 years ago
- fix #704 — committed to yubaolee/docsify by yubaolee 5 years ago
- Temp fix until https://github.com/docsifyjs/docsify/issues/704 gets fixed: In order to use, just build then pack the dependency: ``` npm run build npm pack packages/docsify-server-renderer/ ``` — committed to jliben/docsify by deleted user 5 years ago
- fix: ssr TypeError: Cannot read property 'indexOf' of undefined See this problem in issue: https://github.com/docsifyjs/docsify/issues/704 — committed to DYSDF/docsify by deleted user 3 years ago
- fix: ssr TypeError: Cannot read property 'indexOf' of undefined See this problem in issue: https://github.com/docsifyjs/docsify/issues/704 — committed to DYSDF/docsify by deleted user 3 years ago
All works with old 4.1.7 version.
Last version 4.3.0 returns error
It seems that the examples on docsify-ssr-demo are incomplete and incorrect. I don’t know why.
I don’t know how https://docsify.now.sh/ssr is implemented.
I’ve the exact same error. I’m trying to use docsify with SSR using docsify-server-renderer but seems impossible. Also, the documentation talks about a renderer.renderToString(url) but it’s not explained what the “url” parameter should be.
@QingWei-Li Can you take a look, please?
I looked around the code, and found the possible reason:
_renderFileis called, for absolute paths, the function usesfetchto get file.file://scheme, the fetch won’t work.The same error found, even upgrade to the latest version of docsify 4.3
The same error found, even upgrade to the latest version of docsify