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

Module parse failed: Unexpected character '�' (1:0) #5379

Open
5 tasks done
Redish101 opened this issue Dec 9, 2023 · 1 comment
Open
5 tasks done

Module parse failed: Unexpected character '�' (1:0) #5379

Redish101 opened this issue Dec 9, 2023 · 1 comment
Labels
need-information Further information is requested

Comments

@Redish101
Copy link

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

Use hexo api in a nextjs project.

Actual behavior

It threw "Module parse failed: Unexpected character '�' (1:0)" in this code

import Hexo from "hexo";
import path from "path";
import { cache } from "react";

const initHexo = cache(async () => {
    const hexo = new Hexo()
    await hexo.init()
})

export {
    initHexo
}

How to reproduce?

  1. Create a next.js project
  2. Use hexo api in a nextjs page.

Is the problem still there under Safe mode?

Yes

Your Node.js & npm version

v18.16.0
9.5.1

Your Hexo and Plugin version

├── @eslint-community/[email protected] extraneous -> ./node_modules/.pnpm/@[email protected][email protected]/node_modules/@eslint-community/eslint-utils
├── @eslint-community/[email protected] extraneous -> ./node_modules/.pnpm/@[email protected]/node_modules/@eslint-community/regexpp
├── @eslint/[email protected] extraneous -> ./node_modules/.pnpm/@[email protected]/node_modules/@eslint/eslintrc
├── @eslint/[email protected] extraneous -> ./node_modules/.pnpm/@[email protected]/node_modules/@eslint/js
├── @next/[email protected] extraneous -> ./node_modules/.pnpm/@[email protected]/node_modules/@next/eslint-plugin-next
├── @retalkgo/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@retalkgo/client
├── @rushstack/[email protected] extraneous -> ./node_modules/.pnpm/@[email protected]/node_modules/@rushstack/eslint-patch
├── @types/[email protected] extraneous -> ./node_modules/.pnpm/@[email protected]/node_modules/@types/eslint-scope
├── @types/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@types/marked
├── @types/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@types/md5
├── @types/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@types/node
├── @types/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@types/nprogress
├── @types/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@types/prismjs
├── @types/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@types/react-dom
├── @types/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@types/react
├── @typescript-eslint/[email protected] extraneous -> ./node_modules/.pnpm/@[email protected]/node_modules/@typescript-eslint/scope-manager
├── @typescript-eslint/[email protected] extraneous -> ./node_modules/.pnpm/@[email protected]/node_modules/@typescript-eslint/types
├── @typescript-eslint/[email protected] extraneous -> ./node_modules/.pnpm/@[email protected]/node_modules/@typescript-eslint/visitor-keys
├── @vercel/[email protected] -> ./node_modules/.pnpm/@[email protected]/node_modules/@vercel/analytics
├── [email protected] -> ./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/eslint-config-next
├── [email protected] extraneous -> ./node_modules/.pnpm/[email protected]/node_modules/eslint-import-resolver-node
├── [email protected] extraneous -> ./node_modules/.pnpm/[email protected]_@[email protected][email protected]__nkp6ntjfycjq6yp5liyvdnrfxa/node_modules/eslint-module-utils
├── [email protected] extraneous -> ./node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-react-hooks
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/eslint
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/gray-matter
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/hexo
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/highlight.js
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/highlightjs
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/marked
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/md5
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/moment
├── [email protected] -> ./node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/next
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/nprogress
├── [email protected] -> ./node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/react
├── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/remark
├── [email protected] -> ./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/style9-webpack
├── [email protected] -> ./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/style9
└── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/typescript

Your package.json

{
  "name": "blog-next",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@retalkgo/client": "0.1.0-alpha.9",
    "@types/marked": "^5.0.0",
    "@types/md5": "^2.3.4",
    "@types/node": "20.4.1",
    "@types/nprogress": "^0.2.0",
    "@types/prismjs": "^1.26.0",
    "@types/react": "18.2.14",
    "@types/react-dom": "18.2.6",
    "@vercel/analytics": "^1.0.1",
    "eslint": "8.44.0",
    "eslint-config-next": "13.4.9",
    "gray-matter": "^4.0.3",
    "hexo": "^7.0.0",
    "highlight.js": "^11.8.0",
    "highlightjs": "^9.16.2",
    "marked": "^5.1.1",
    "md5": "^2.3.0",
    "moment": "^2.29.4",
    "next": "13.4.10",
    "nprogress": "^0.2.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "remark": "^14.0.3",
    "style9": "^0.18.2",
    "style9-webpack": "^0.5.0",
    "typescript": "5.1.6"
  }
}

Your site's _config.yml (Optional)

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

# Site
title: Hexo
subtitle: ''
description: ''
keywords:
author: John Doe
language: en
timezone: ''

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://example.com
permalink: :year/:month/:day/:title/
permalink_defaults:
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:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link:
  enable: true # 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
syntax_highlighter: highlight.js
highlight:
  line_number: true
  auto_detect: false
  tab_replace: ''
  wrap: true
  hljs: false
prismjs:
  preprocess: true
  line_number: true
  tab_replace: ''

# 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
## updated_option supports 'mtime', 'date', 'empty'
updated_option: 'mtime'

# 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: landscape

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
  type: ''

Others

No response

@uiolee uiolee added the need-information Further information is requested label Dec 22, 2023
@ChrAlpha
Copy link

ChrAlpha commented Feb 24, 2024

If this error is threw by something like fsevents.node and you're using macOS, maybe you should configure node-loader as webpack's loader for node files.
It's wired since everything just run expectively correctly on Ubuntu.

Especially for Next.js project. Try adding following configuration to next.config.js:

  webpack: (config, options) => {
    config.module.rules.push({
      test: /\.node/,
      loader: "node-loader",
    });

    return config;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-information Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants