bug: error in `dev` command when specifying a an entry file in an adjacent directory
Describe the bug
- When you run slidev and specify a markdown entry file that is in the same directory as the slidev project --> OK
- When you run slidev and specify a markdown entry file that is in a sibling directory as the slidev project --> ERROR
- Using a symbolic link appears to workaround this error
- However, relative paths within that file are interpreted differently, creating a different problem
Minimal reproduction
Steps to reproduce the behavior:
pnpm dev ../mod02/slides.md
Yields this error:
file:///Users/user/code/hedera/hedera-dev-course-101/slidev/node_modules/@slidev/cli/dist/chunk-UNQ5DBLZ.js:42
throw new Error(`Failed to resolve package "${dep}"`);
^
Error: Failed to resolve package "@slidev/theme-default"
at findPkgRoot (file:///Users/user/code/hedera/hedera-dev-course-101/slidev/node_modules/@slidev/cli/dist/chunk-UNQ5DBLZ.js:42:11)
at async file:///Users/user/code/hedera/hedera-dev-course-101/slidev/node_modules/@slidev/cli/dist/chunk-UNQ5DBLZ.js:118:22
at async resolveOptions (file:///Users/user/code/hedera/hedera-dev-course-101/slidev/node_modules/@slidev/cli/dist/chunk-UAXJBAYZ.js:2605:30)
at async initServer (file:///Users/user/code/hedera/hedera-dev-course-101/slidev/node_modules/@slidev/cli/dist/cli.js:131:23)
Node.js v23.3.0
ELIFECYCLE Command failed with exit code 1.
Note that it also prompts the following every time, even though the theme is installed.
? The theme "@slidev/theme-default" was not found in your project, do you want to install it now? › (Y/n)
Workaround to avoid this behaviour:
ln -s ../mod02/slides.md mod02-slides.md
pnpm dev mod02-slides.md
Environment
- Slidev version:
"dependencies": {
"@slidev/cli": "^51.1.0",
"@slidev/theme-default": "^0.25.0",
"@slidev/theme-seriph": "latest",
"vue": "^3.5.13"
}
- Browser: Chrome - Version 132.0.6834.84 (Official Build) (arm64)
- OS: Mac OSX
@kermanx LMK if you were able to reproduce this! I wanna know if it's just me or it actually is a bug in slidev. If it's the former, what I am doing wrong.
Inferred from the stacktrace, did you mean:
cd /Users/user/code/hedera/hedera-dev-course-101/slidev/
pnpm dev ../mod02/slides.md
In this case, it errors because packages will be resolved from where the slides.md is, but the node_modules is not in its parent directory. You may need to move the package.json to /Users/user/code/hedera/hedera-dev-course-101/ and re-install it.
@kermanx ah ok, so using sibling directories could work as long as the node_modules and package.json file are in the common parent directory?
OK, will try that.
@kermanx tried what you suggested, and it results in some strange behaviour, where the slides run but they render as empty, and in the terminal, I get this output:
Unknown layout "module_title_start". Available layouts are:
404 center cover
default end error
fact full iframe-left
iframe-right iframe image-left
image-right image intro
none quote section
statement two-cols-header two-cols
(repeated for each custom layout that I have, replace module_title_start)
This approach seems to introduce more problems, I think it might be better if there was a fix in slidev such that it is able to process/ display markdown files in sibling directories, even when package.json etc are in the current directory.
Perhaps one way of implementing this could be to add a CLI flag to specify what the slidev root directory to us should be. (If not specifies, uses the current directory, which is what it does right now)
is there any update on this problem? This is very strange behavior and was really hard to track down, I spent hours and hours trying to figure out what I was doing wrong just to find out its "expected."
Seems like slidev should just load the markdown and not require having node_modules etc in the same folder as the markdown, or if thats the behavior why even allow passing in a file in another directory?