hexojs / hexojs/hexo

.j2 file in code_dir causing rendering error

Open
#5,479 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
41.8k
Forks
41
PR merge metrics
No merged PRs in 30d

Description

### Check List

- [X] I have already read [Docs page](https://hexo.io/docs/) & [Troubleshooting page](https://hexo.io/docs/troubleshooting).
- [X] I have already searched existing issues and they are not help to me.
- [X] I examined error or warning messages and it's difficult to solve.
- [X] I am using the [latest](https://github.com/hexojs/hexo/releases) version of Hexo. (run `hexo version` to check)
- [X] My Node.js is matched [the required version](https://hexo.io/docs/#Required-Node-js-version).

### Expected behavior

`.j2` files in `code_dir` folder should not breaks `hexo generate`

### Actual behavior

`hexo generate` will fail. (see the reproducing steps)

### How to reproduce?

```
hexo init hexo-test
cd hexo-test

mkdir -p source/downloads/code
touch source/downloads/code/j2-test.j2

echo '{% include_code j2-test.j2 j2-test.j2 %}' >> source/_posts/hello-world.md

hexo clean && hexo generate --debug
```

Gives the following error:

```
06:30:54.928 FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Template render error: (unknown path)
TypeError: Cannot read properties of undefined (reading 'split')
at Object._prettifyError (/Users/jinzhouz/tmp/hexo-test/node_modules/nunjucks/src/lib.js:32:11)
at /Users/jinzhouz/tmp/hexo-test/node_modules/nunjucks/src/environment.js:464:19
at eval (eval at _compile (/Users/jinzhouz/tmp/hexo-test/node_modules/nunjucks/src/environment.js:527:18), :11:11)
at tryCatcher (/Users/jinzhouz/tmp/hexo-test/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/jinzhouz/tmp/hexo-test/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/jinzhouz/tmp/hexo-test/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromiseCtx (/Users/jinzhouz/tmp/hexo-test/node_modules/bluebird/js/release/promise.js:641:10)
at _drainQueueStep (/Users/jinzhouz/tmp/hexo-test/node_modules/bluebird/js/release/async.js:97:12)
at _drainQueue (/Users/jinzhouz/tmp/hexo-test/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/jinzhouz/tmp/hexo-test/node_modules/bluebird/js/release/async.js:102:5)
at Async.drainQueues (/Users/jinzhouz/tmp/hexo-test/node_modules/bluebird/js/release/async.js:15:14)
at process.processImmediate (node:internal/timers:478:21)
```

### Is the problem still there under `Safe mode`?

no

### Your Node.js & npm version

```text
v21.4.0
10.2.4
```

### Your Hexo and Plugin version

```text
hexo-site@0.0.0 /Users/jinzhouz/tmp/hexo-test
├── hexo-generator-archive@2.0.0
├── hexo-generator-category@2.0.0
├── hexo-generator-index@3.0.0
├── hexo-generator-tag@2.0.0
├── hexo-renderer-ejs@2.0.0
├── hexo-renderer-marked@6.3.0
├── hexo-renderer-stylus@3.0.1
├── hexo-server@3.0.0
├── hexo-theme-landscape@1.0.0
└── hexo@7.2.0
```

### Your `package.json`

```json
{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "hexo generate",
"clean": "hexo clean",
"deploy": "hexo deploy",
"server": "hexo server"
},
"hexo": {
"version": "7.2.0"
},
"dependencies": {
"hexo": "^7.0.0",
"hexo-generator-archive": "^2.0.0",
"hexo-generator-category": "^2.0.0",
"hexo-generator-index": "^3.0.0",
"hexo-generator-tag": "^2.0.0",
"hexo-renderer-ejs": "^2.0.0",
"hexo-renderer-marked": "^6.0.0",
"hexo-renderer-stylus": "^3.0.0",
"hexo-server": "^3.0.0",
"hexo-theme-landscape": "^1.0.0"
}
}
```

### Your site's `_config.yml` (Optional)

_No response_

### Others

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.