(link.children[0] || "").split is not a function
nweldev opened this issue · 12 comments
Version
- vuepress-bar: 0.2.5
- Node.js: 13.12.0
- vuepress: 1.3.1
Config
const getConfig = require("vuepress-bar");
const barConfig = getConfig(`${__dirname}/..`, {
addReadMeToFirstGroup: false,
stripNumbers: false
});
Sources
- 0-foo/
- 1-lorem.md
- TITLE.md
- 1-bar/
- 5-ipsum/
- 1-something.md
- 2-something-else.md
- TITLE.md
- TITLE.md
- 5-ipsum/
- 2-baz/
- 5-boo/
- 1-something.md
- 2-something-else.md
- TITLE.md
- TITLE.md
- 5-boo/
- implicit/
- callback/
- index.md
- callback/
Where implicit/callback/index.md
is
---
public: true
---
# Logging In
<!-- markdownlint-disable no-inline-html -->
<AuthCallback />
Error
$ vuepress build src
wait Extracting site metadata...
TypeError: (link.children[0] || "").split is not a function
at /home/user/git/project/node_modules/vuepress-bar/lib/index.js:129:72
at Array.findIndex (<anonymous>)
at /home/user/git/project/node_modules/vuepress-bar/lib/index.js:128:50
at Array.forEach (<anonymous>)
at side (/home/user/git/project/node_modules/vuepress-bar/lib/index.js:119:8)
at getConfig (/home/user/git/project/node_modules/vuepress-bar/lib/index.js:294:84)
at Object.<anonymous> (/home/user/git/project/src/.vuepress/config.js:2:19)
at Module._compile (internal/modules/cjs/loader.js:1147:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
at Module.load (internal/modules/cjs/loader.js:996:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Module.require (internal/modules/cjs/loader.js:1036:19)
at require (internal/modules/cjs/helpers.js:72:18)
at loadConfig (/home/user/git/project/node_modules/@vuepress/core/lib/node/loadConfig.js:31:18)
at App.resolveConfigAndInitialize (/home/user/git/project/node_modules/@vuepress/core/lib/node/App.js:64:24)
at App.process (/home/user/git/project/node_modules/@vuepress/core/lib/node/App.js:1
debug infos
https://github.com/ozum/vuepress-bar/blob/v0.2.5/lib/index.js#L129: link
is equal to the json below before this line throws the error above.
{
"title": "Implicit",
"children": [
{
"title": "Callback",
"children": [
"implicit/callback/index"
]
}
]
}
@noelmace, if you have time to create a failing test, I'll be happy to help. I'll let this case open for a while.
@ozum
I'm experiencing same issue..
I guess it is caused by folders without .md file
For example,the situation below emits error. (Becuase folderA doesn't have .md file)
folderA/folderB/README.md
@darron1217, I would like to help. Assuming you are using latest version, could you please create a failing test in docs directory. Also please take a look docs/example-deep-readme
@ozum
I copied docs folder in this repo, and it generates same error.
OS : Win10 pro
node : v8.11.2
npm : 6.14.4
package.json
"dependencies": {
"markdown-it-disable-url-encode": "^1.0.1",
"vuepress": "^1.4.1",
"vuepress-bar": "^0.3.0",
"vuepress-plugin-fulltext-search": "^2.0.2"
}
config.js
const menuConfig = require("vuepress-bar")(`${__dirname}/..`, {
maxLevel: 4,
addReadMeToFirstGroup: false
});
module.exports = {
title: "IT메뉴얼",
description: "IT팀 메뉴얼",
dest: "public",
base: "/it-asset-management/",
plugins: ['fulltext-search'],
themeConfig: {
...menuConfig
},
markdown: {
extendMarkdown: md => {
md.use(require("markdown-it-disable-url-encode"));
}
}
}
Please provide a sample repo, or sandbox showing error for me to investigate.
I console.log it.
The code i use for debug
const sortedFolderPosition = fileLinks.findIndex(
link => {
console.log(link.children[0]);
return subDir < (link.children ? (link.children[0] || "").split(sep)[0] : link);
}
);
result
wait Extracting site metadata...
example-no-navbar/01.guide/
{ title: 'Guide',
children: [ { title: 'Chapter 1', children: [Array] } ] }
TypeError: (link.children[0] || "").split is not a function
@ozum
Here's sandbox. Just run yarn dev
and you'll get an error.
https://codesandbox.io/s/codesandbox-vuepress-83yuf?file=/package.json
@ozum
I created PR to fix this problem.
BTW would you reopen this issue?
Thanks @darron1217 for the PR. I merged and published to npm.
@noelmace, could you please test latest version with darron1217's PR, whether it solves your issue?
This patch has broken stripNumbers: true
.
If stripNumbers: true
then sorting does not work.
@talha131
stripNumbers
option is true
by default.
And i didn't touch original functionality. The modification i did is just handling exceptional situtation.
I guess it is just problem that exist before. Not related to this issue.
BTW would you create sandbox url that reproduces problem?
The latest sandbox I made is link below.
https://codesandbox.io/s/codesandbox-vuepress-83yuf?file=/package.json
@darron1217 thank you for your prompt response. The issue was in my configuration.
When I looked at my site in detail, it turned out that one of the folders that contained several subfolders did not have a README.md
file in the root. This pushed the folder to the bottom. Adding README.md
fixed the issue.