Skip to content
New issue

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

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

Already on GitHub? # to your account

Misleading Nunjucks error message #3859

Closed
5 tasks done
TingxunShi opened this issue Nov 13, 2019 · 20 comments
Closed
5 tasks done

Misleading Nunjucks error message #3859

TingxunShi opened this issue Nov 13, 2019 · 20 comments
Labels
enhancement New feature or request

Comments

@TingxunShi
Copy link

TingxunShi commented Nov 13, 2019

Check List

Please check followings before submitting a new issue.

  • 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
  • Using the latest version of Hexo (run hexo version to check)
  • Node.js is higher than 8.6.0

Question

Error message below is shown (I'm sure that I have filled in url: field in my hexo _config.yml)

[myname@myname-pc blog_src]$ hexo g
INFO  Start processing
INFO  Files loaded in 378 ms
ERROR Render HTML failed: about/index.html
TypeError: Cannot read property 'replace' of null
    at Hexo.externalLinkFilter (/home/myname/Projects/blog_src/node_modules/hexo/lib/plugins/filter/after_render/external_link.js:45:15)                                                                                                                               
    at Hexo.tryCatcher (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/util.js:16:23)
    at Hexo.<anonymous> (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/method.js:15:34)
    at /home/myname/Projects/blog_src/node_modules/hexo/lib/extend/filter.js:60:50
    at tryCatcher (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/util.js:16:23)
    at Object.gotValue (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/reduce.js:166:18)
    at Object.gotAccum (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/reduce.js:155:25)
    at Object.tryCatcher (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromiseCtx (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/promise.js:641:10)
    at _drainQueueStep (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/async.js:97:12)
    at _drainQueue (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/myname/Projects/blog_src/node_modules/bluebird/js/release/async.js:15:14)                                                                                                                                  
    at processImmediate (internal/timers.js:439:21)

Environment & Settings

Node.js & npm version

hexo: 4.0.0
hexo-cli: 3.1.0
os: Linux 5.3.8-3-MANJARO linux x64
node: 13.1.0
v8: 7.8.279.17-node.19
uv: 1.33.1
zlib: 1.2.11
brotli: 1.0.7
ares: 1.15.0
modules: 79
nghttp2: 1.39.2
napi: 5
llhttp: 1.1.4
openssl: 1.1.1d
cldr: 35.1
icu: 64.2
tz: 2019a
unicode: 12.1

Your site _config.yml (Optional)

Your theme _config.yml (Optional)

Hexo and Plugin version(npm ls --depth 0)

hexo-site@0.0.0 /home/txshi/Projects/blog_src
├── hexo@4.0.0
├── hexo-generator-archive@1.0.0
├── hexo-generator-category@1.0.0
├── hexo-generator-index@1.0.0
├── hexo-generator-tag@1.0.0
├── hexo-renderer-ejs@1.0.0
├── hexo-renderer-marked@2.0.0
├── hexo-renderer-stylus@1.1.0
└── hexo-server@1.0.0

Your package.json 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": "4.0.0"
  },
  "dependencies": {
    "hexo": "^4.0.0",
    "hexo-generator-archive": "^1.0.0",
    "hexo-generator-category": "^1.0.0",
    "hexo-generator-index": "^1.0.0",
    "hexo-generator-tag": "^1.0.0",
    "hexo-renderer-ejs": "^1.0.0",
    "hexo-renderer-stylus": "^1.1.0",
    "hexo-renderer-marked": "^2.0.0",
    "hexo-server": "^1.0.0"
  }
}

Others

@curbengh
Copy link
Contributor

curbengh commented Nov 27, 2019

Does source/about/index.md have any content?

Can you try disable external_link: and run hexo clean && hexo g?

external_link:
  enable: false

@a-runner
Copy link

a-runner commented Dec 2, 2019

i have the same problem!

@TingxunShi
Copy link
Author

Does source/about/index.md have any content?

Can you try disable external_link: and run hexo clean && hexo g?

external_link:
  enable: false

Hi @curbengh , sorry for the late reply. I have something in source/about/index.md.

I tried to disable external_link and generation did worked. However when I ran hexo s and visited localhost:4000, there is nothing in the browser but only a "null" in the top left corner

@yszar
Copy link

yszar commented Dec 31, 2019

Does source/about/index.md have any content?
Can you try disable external_link: and run hexo clean && hexo g?

external_link:
  enable: false

Hi @curbengh , sorry for the late reply. I have something in source/about/index.md.

I tried to disable external_link and generation did worked. However when I ran hexo s and visited localhost:4000, there is nothing in the browser but only a "null" in the top left corner

i have the same problem!

@hcoona
Copy link
Contributor

hcoona commented Jan 15, 2020

Does source/about/index.md have any content?

Can you try disable external_link: and run hexo clean && hexo g?

external_link:
  enable: false

@curbengh This doesn't work for my case. Turned it off, the error message changed into following:

ERROR Cannot read property 'replace' of null
TypeError: Cannot read property 'replace' of null
    at Hexo.externalLinkFilter (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\hexo\lib\plugins\filter\after_render\external_link.js:22:15)
    at Hexo.tryCatcher (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.<anonymous> (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\method.js:15:34)
    at C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\hexo\lib\extend\filter.js:62:52
    at tryCatcher (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\util.js:16:23)
    at Object.gotValue (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\reduce.js:166:18)
    at Object.gotAccum (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\reduce.js:155:25)
    at Object.tryCatcher (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromiseCtx (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\promise.js:641:10)
    at _drainQueueStep (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\async.js:97:12)
    at _drainQueue (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

My package.json:

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "4.2.0"
  },
  "dependencies": {
    "hexo": "^4.2.0",
    "hexo-deployer-git": "^2.1.0",
    "hexo-filter-auto-spacing": "^0.2.1",
    "hexo-front-matter-excerpt": "^0.2.0",
    "hexo-generator-archive": "^1.0.0",
    "hexo-generator-baidu-sitemap": "^0.1.2",
    "hexo-generator-category": "^1.0.0",
    "hexo-generator-feed": "^2.2.0",
    "hexo-generator-index": "^1.0.0",
    "hexo-generator-sitemap": "^2.0.0",
    "hexo-generator-tag": "^1.0.0",
    "hexo-renderer-asciidoc": "^1.2.2",
    "hexo-renderer-ejs": "^1.0.0",
    "hexo-renderer-marked": "^2.0.0",
    "hexo-renderer-stylus": "^1.1.0",
    "hexo-server": "^1.0.0"
  }
}

@hcoona
Copy link
Contributor

hcoona commented Jan 15, 2020

I tried to establish Hexo site from scratch but still failed to generate HTMLs because of this issue.

  1. Run hexo init blog
  2. Clone NexT theme into themes/next
  3. Run yarn add hexo-renderer-asciidoc & resolve the hexo-util version to "^1.8.1"
  4. Modify _config.yml carefully.
  5. Copy my source folder to the current project.

When the external_link.enabled set to true, it failed to generate HTMLs with the following error:

ERROR Render HTML failed: categories/index.html
TypeError: Cannot read property 'replace' of null
    at Hexo.externalLinkFilter (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\hexo\lib\plugins\filter\after_render\external_link.js:22:15)
    at Hexo.tryCatcher (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.<anonymous> (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\method.js:15:34)
    at C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\hexo\lib\extend\filter.js:62:52
    at tryCatcher (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\util.js:16:23)
    at Object.gotValue (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\reduce.js:166:18)
    at Object.gotAccum (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\reduce.js:155:25)
    at Object.tryCatcher (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromiseCtx (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\promise.js:641:10)
    at _drainQueueStep (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\async.js:97:12)
    at _drainQueue (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\GitEnlistments\gitlab.com\zhangshuai-blog\node_modules\bluebird\js\release\async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

When the external_link.enabled set to false, the generation process succeeded, but all index.html content is "null".

My packages.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": "4.2.0"
  },
  "dependencies": {
    "hexo": "^4.0.0",
    "hexo-generator-archive": "^1.0.0",
    "hexo-generator-category": "^1.0.0",
    "hexo-generator-index": "^1.0.0",
    "hexo-generator-tag": "^1.0.0",
    "hexo-renderer-asciidoc": "^1.2.2",
    "hexo-renderer-ejs": "^1.0.0",
    "hexo-renderer-marked": "^2.0.0",
    "hexo-renderer-stylus": "^1.1.0",
    "hexo-server": "^1.0.0",
    "hexo-util": "^1.8.1"
  },
  "resolutions": {
    "hexo-renderer-asciidoc/**/hexo-util": "^1.8.1"
  }
}

My _config.yml:

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: ...
subtitle: ''
description: ''
keywords:
author: ...
language: "zh-CN"
timezone: "Asia/Hong_Kong"

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: ...
root: /
permalink: :category/:title/
permalink_defaults:
  lang: zh
pretty_urls:
  trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
  trailing_html: true # Set to false to remove trailing '.html' from permalinks

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
  - assets/**

# Writing
new_post_name: :year-:month-:day-:title.adoc # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link:
  enable: false # Open external links in new tab
  field: site # Apply to the whole site
  exclude: ''
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: false
  auto_detect: false
  tab_replace: '  '
  wrap: true
  hljs: false

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
  path: ''
  per_page: 10
  order_by: -date

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Metadata elements
## https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
meta_generator: true

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
## Use post's date for updated date unless set in front-matter
use_date_for_updated: false

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Include / Exclude file(s)
## include:/exclude: options only apply to the 'source/' folder
include:
exclude:
ignore:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next
theme_config:
  reminder: false
  codeblock:
    highlight_theme: night
  creative_commons:
    license: by-nc-nd
    sidebar: true
    post: true
    language: deed.zh
  custom_file_path:
    style: source/_data/styles.styl
  fancybox: true
  footer:
    since: 2011
  math:
    per_page: false
    mathjax:
      enable: true
  menu:
    categories: /categories/ || th
    tags: /tags/ || tags
    about: /about/ || user
  pangu: true
  sidebar:
    position: right
    display: post

I already tried hexo clean && hexo g --force.

@hcoona
Copy link
Contributor

hcoona commented Jan 15, 2020

I finally found the social links in next config matters. The error would disappear if I remove theme_config.social.

More specifically, the link without font awesome target matters, for example:

  social:
    GitHub: http://... || github # This works fine
    ZhiHu: http://..... # This matters

@hcoona
Copy link
Contributor

hcoona commented Jan 15, 2020

Also found hexo-renderer-asciidoc would hit this error, fixed by upgrading it to v2.0.0

@cugxuan
Copy link

cugxuan commented Jan 29, 2020

I finally found the social links in next config matters. The error would disappear if I remove theme_config.social.

More specifically, the link without font awesome target matters, for example:

  social:
    GitHub: http://... || github # This works fine
    ZhiHu: http://..... # This matters

I also find this question!!!

@TingxunShi
Copy link
Author

I finally found the social links in next config matters. The error would disappear if I remove theme_config.social.

More specifically, the link without font awesome target matters, for example:

  social:
    GitHub: http://... || github # This works fine
    ZhiHu: http://..... # This matters

Great solution!

@tedburner
Copy link

I finally found the social links in next config matters. The error would disappear if I remove theme_config.social.

More specifically, the link without font awesome target matters, for example:

  social:
    GitHub: http://... || github # This works fine
    ZhiHu: http://..... # This matters

i find the same question, and can resolve the question. the hexo-theme-next has the question?

@xu-song
Copy link
Contributor

xu-song commented May 28, 2020

Does source/about/index.md have any content?
Can you try disable external_link: and run hexo clean && hexo g?

external_link:
  enable: false

Hi @curbengh , sorry for the late reply. I have something in source/about/index.md.
I tried to disable external_link and generation did worked. However when I ran hexo s and visited localhost:4000, there is nothing in the browser but only a "null" in the top left corner

i have the same problem!

+1.

I have the same problem too. Have u solve this issue @TingxunShi @yszar 

theme-next has the above problem. theme landscape works fine.

@stevenjoezhang stevenjoezhang changed the title TypeError: Cannot read property 'replace' of null (url in _config.yml is filled) Misleading Nunjucks error message Jul 12, 2020
@stevenjoezhang stevenjoezhang added the enhancement New feature or request label Jul 12, 2020
@stevenjoezhang
Copy link
Member

stevenjoezhang commented Jul 12, 2020

The Nunjucks renderer has become part of Hexo, thus I think it is necessary to reconsider this issue. Since Nunjucks returns null instead of an empty string when it encounters a rendering error, some Hexo plugins will throw errors when trying to execute the String.prototype.replace function. The error message is misleading, and the original error message of Nunjucks is not displayed.

Relevant issues #4313 #4241

@SukkaW
Copy link
Member

SukkaW commented Jul 15, 2020

Since Nunjucks returns null instead of an empty string when it encounters a rendering error

We could add a failsafe by returning an empty string.

the original error message of Nunjucks is not displayed.

Help is needed.

@12121-12121
Copy link

Nunjucks渲染器已成为Hexo的一部分,因此我认为有必要重新考虑此问题。由于Nunjucks遇到渲染错误时会返回null而不是空字符串,因此某些Hexo插件在尝试执行该String.prototype.replace功能时会抛出错误。该错误消息具有误导性,并且不显示Nunjucks的原始错误消息。

相关问题#4313 #4241

多谢,那...,该如何解决此问题呢?

@stevenjoezhang
Copy link
Member

@12121-12121 是否方便提供 source/_data/footer.swig 的内容?

@12121-12121
Copy link

我终于在下一个配置问题中找到了社交链接。如果删除,该错误将消失theme_config.social

更具体地说,没有字体目标的链接很重要,例如:

  social:
    GitHub: http://... || github # This works fine
    ZhiHu: http://..... # This matters

您能详细的说一下吗?

@12121-12121
Copy link

@ 12121-12121是否方便提供source/_data/footer.swig的内容?

当然。

<script color="88,87,86" opacity="0.5" zIndex="-1" count="125" src="https://cdn.jsdelivr.net/npm/canvas-nest.js@1/dist/canvas-nest.js"></script>

@stevenjoezhang
Copy link
Member

@SukkaW See also mozilla/nunjucks#1272 mozilla/nunjucks#1301

@12121-12121 你遇到的 bug 似乎和这里讨论的问题不同,建议到你新开的 Issue 中讨论 #4419

@SukkaW
Copy link
Member

SukkaW commented Jul 20, 2020

@stevenjoezhang It appears that the newest Nunjucks has been released.

I will bring up a PR to update to latest Nunjucks and bring up a test case accordingly.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests