Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法运行yarn start命令 #302

Open
gittig11 opened this issue Oct 28, 2021 · 4 comments
Open

无法运行yarn start命令 #302

gittig11 opened this issue Oct 28, 2021 · 4 comments

Comments

@gittig11
Copy link

安装依赖,运行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

原因未知...

@waytoviva
Copy link

waytoviva commented Nov 23, 2021

遇到跟你一样的问题, run build 和 start 都是 包跟你一样的错误, ENOENT: no such file or directory, open 'C:...\registry.npmmirror.com+markdown-to-html-cli@3.1.6\node_modules\markdown-to-html-cli\package.json'
不管是npm 还是 pnpm 都一样是报这个错
node v14.16.1
npm v7.23.0
pnpm v6.23.1

@jaywcjlove
Copy link
Owner

image

@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

@gittig11
Copy link
Author

@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'));
为什么这里的路径有问题,时间原因没有深入了解。

@jaywcjlove
Copy link
Owner

jaywcjlove commented Nov 24, 2021

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.

@gittig11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants