Skip to content

.j2 file in code_dir causing rendering error #5479

@lotabout

Description

@lotabout

Check List

  • I have already read Docs page & Troubleshooting page.
  • I have already searched existing issues and they are not help to me.
  • I examined error or warning messages and it's difficult to solve.
  • I am using the latest version of Hexo. (run hexo version to check)
  • My Node.js is matched the required 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), <anonymous>: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

v21.4.0
10.2.4

Your Hexo and Plugin version

[email protected] /Users/jinzhouz/tmp/hexo-test
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Your package.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions