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

打开后界面显示错误:ENOENT:没有这样的文件或目录,打开“themes/shoka/source/js/_app/utils.js” #39

Closed
wcl0755bigdata opened this issue Sep 19, 2023 · 5 comments

Comments

@wcl0755bigdata
Copy link

日志中显示:InternalServerError: Error: ENOENT: no such file or directory, open 'themes/shoka/source/js/_app/utils.js',是不是缺少什么设置?

@YuJianghao
Copy link
Contributor

不像是缺少什么 hexon 设置,可能是因为存在 shoka 主题导致的问题。可以尝试下:

  • themes/shoka/source/js/_app/utils.js 文件是否真的不存在?
  • shoka 主题是否在 hexo 正确配置?
  • 更换 hexo 默认主题是否也有相同问题?
  • 报错前执行了什么操作,有无更详细的报错信息或截图?

@wcl0755bigdata
Copy link
Author

我的hexo显示正常,hexon是刚安装的,现在用临时办法解决了这个问题,方法是把“themes/shoka/source/js/_app/utils.js”这个文件及路径在hexon的server目录下复制了一份,不知道是不是我对整体架构的理解有问题,目前blog路径d:\doc\blog和hexon路径d:\dev\hexon是分开的

@YuJianghao
Copy link
Contributor

YuJianghao commented Sep 22, 2023

似乎在读取这个文件的时候 hexon 使用了错误的 cwd。默认主题或者其他主题也会出现此问题么?

@wcl0755bigdata
Copy link
Author

默认主题没有问题

@YuJianghao
Copy link
Contributor

[hexo-instance-service][2023-09-26 11:34:51.479] Error: ENOENT: no such file or directory, open 'themes/shoka/source/js/_app/utils.js'
    at Object.openSync (node:fs:590:3)
    at Object.readFileSync (node:fs:458:35)
    at Object.readFileSync (~/works/dev/test-blog/node_modules/hexo-fs/lib/fs.js:229:22)
    at ~/works/dev/test-blog/themes/shoka/scripts/generaters/script.js:60:16
    at Array.forEach (<anonymous>)
    at Hexo.<anonymous> (~/works/dev/test-blog/themes/shoka/scripts/generaters/script.js:59:67)
    ... {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: 'themes/shoka/source/js/_app/utils.js'
}

定位了下:

themes/shoka/scripts/generaters/script.js 会调用 hexo-fs 但是获取了当前 cwd, 也就是 hexon 目录。可以改到 hexo 的 cwd:

diff --git a/scripts/generaters/script.js b/scripts/generaters/script.js
index 370ff7b..f5212c9 100644
--- a/scripts/generaters/script.js
+++ b/scripts/generaters/script.js
@@ -1,9 +1,11 @@
 'use strict';
 const fs = require('hexo-fs');
 const url = require('url');
+const {resolve} = require('path')
 
 
 hexo.extend.generator.register('script', function(locals){
+  const cwd = this.base_dir
   const config = hexo.config;
   const theme = hexo.theme.config;
 
@@ -57,11 +59,11 @@ hexo.extend.generator.register('script', function(locals){
   var text = '';
 
   ['utils', 'dom', 'player', 'global', 'sidebar', 'page', 'pjax'].forEach(function(item) {
-    text += fs.readFileSync('themes/shoka/source/js/_app/'+item+'.js').toString();
+    text += fs.readFileSync(resolve(cwd, 'themes/shoka/source/js/_app/'+item+'.js')).toString();
   });
 
   if(theme.fireworks && theme.fireworks.enable) {
-    text += fs.readFileSync('themes/shoka/source/js/_app/fireworks.js').toString();
+    text += fs.readFileSync(resolve(cwd, 'themes/shoka/source/js/_app/fireworks.js')).toString();
     siteConfig.fireworks = theme.fireworks.color || ["rgba(255,182,185,.9)", "rgba(250,227,217,.9)", "rgba(187,222,214,.9)", "rgba(138,198,209,.9)"]
   }

如果还有问题,欢迎回复~

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

2 participants