无法运行yarn start命令
安装依赖,运行yarn start后,报错:
fs.js:474
handleErrorFromBinding(ctx);
^
Error: \linux-command\node_modules\markdown-to-html-cli\package.json: ENOENT: no such file or directory, open '\linux-command\node_modules\markdown-to-html-cli\package.json'
at Object.openSync (fs.js:474:3)
at Object.readFileSync (fs.js:375:35)
at Object.readFileSync (\linux-command\node_modules\jsonfile\index.js:50:22)
at /linux-command/node_modules/markdown-to-html-cli/lib/index.js:6:16
at ModuleJob.run (internal/modules/esm/module_job.js:146:23)
at async Loader.import (internal/modules/esm/loader.js:165:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: '\\linux-command\\node_modules\\markdown-to-html-cli\\package.json'
}
node版本 14.13.1
原因未知...
遇到跟你一样的问题, run build 和 start 都是 包跟你一样的错误, ENOENT: no such file or directory, open 'C:...\[email protected]\node_modules\markdown-to-html-cli\package.json' 不管是npm 还是 pnpm 都一样是报这个错 node v14.16.1 npm v7.23.0 pnpm v6.23.1

@gittig11 @waytoviva 我在 macOS 上没有问题。没有 windows 电脑,没有办法调试,尝试解决方案。
➜ linux-command git:(master) npm -v
7.23.0
➜ linux-command git:(master) node -v
v14.17.5
➜ linux-command git:(master) rm -rf package-lock.json node_modules
➜ linux-command git:(master) npm i
@jaywcjlove 找到原因了,markdown-to-html-cli v3.1.6代码有问题,
lib/index.js 中,应为:
// const pkg = fs.readJSONSync(path.resolve(/file:\/\/(.+)\/[^/]/.exec(import.meta.url)[1], '..', 'package.json'));
const pkg = fs.readJSONSync(path.resolve(/file:\/\/\/(.+)\/[^/]/.exec(import.meta.url)[1], '..', 'package.json'));
lib/create.js中,
let cssStr = fs.readFileSync(path.resolve(/file:\/\/\/(.+)\/[^/]/.exec(import.meta.url)[1], 'styles', 'github.css')).toString();
if (options['github-corners-fork'] && options['github-corners']) {
let cssFork = fs.readFileSync(path.resolve(/file:\/\/\/(.+)\/[^/]/.exec(import.meta.url)[1], 'styles', 'github-fork-ribbon.css')).toString();
cssStr = `${cssStr}${cssFork}`;
}
至于
const pkg = fs.readJSONSync(path.resolve(__dirname, '..', 'package.json'));
经过转译后是:
const pkg = fs.readJSONSync(path.resolve(/file:\/\/(.+)\/[^/]/.exec(import.meta.url)[1], '..', 'package.json'));
为什么这里的路径有问题,时间原因没有深入了解。
https://nodejs.org/api/esm.html#esm_no_require_exports_module_exports_filename_dirname
我好像找到原因了。
These CommonJS variables are not available in ES modules. __filename and __dirname use cases can be replicated via import.meta.url.
- https://github.com/jaywcjlove/markdown-to-html-cli/issues/28
@gittig11