4

After upgrading rehype-katex from 5.0.0 to 6.0.1, when I run yarn start, I got:

./node_modules/hast-util-to-text/index.js 363:65
Module parse failed: Identifier directly after number (363:65)
File was processed with these loaders:
 * ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|     //     break is the zero-width space character (U+200B), then the break is
|     //     removed, leaving behind the zero-width space.
>     if (lines[index].charCodeAt(lines[index].length - 1) === 0x20_0b
|     /* ZWSP */
|     || index < lines.length - 1 && lines[index + 1].charCodeAt(0) === 0x20_0b

But it works fine in codesandbox, and yarn build is also OK. How do I fix this?

My package.json:

{
  "name": "blog",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.12.3",
    "@material-ui/icons": "^4.11.2",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^12.0.0",
    "@testing-library/user-event": "^13.2.1",
    "gh-pages": "^3.2.3",
    "pubsub-js": "^1.9.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-helmet": "^6.1.0",
    "react-markdown": "^7.0.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "react-syntax-highlighter": "^15.4.4",
    "rehype-katex": "^6.0.1", // Upgrade
    "rehype-raw": "^6.0.0",
    "remark-gfm": "^2.0.0",
    "remark-math": "^5.0.0",
    "web-vitals": "^2.1.0"
  },
  "scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "homepage": "https://xxx.github.io"
}
  • OS: Linux
  • yarn: v1.22.11
  • nodejs: v16.6.2
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
RayAlto
  • 41
  • 1
  • 5

4 Answers4

2

I had the same error, and it took me longer than I'm willing to admit to find its cause. For me, it was underscores within number literals.

num = 2_000; // bad bad not good
num = 2000; // no probs
1

I had the exactly same problem and have fixed the issue by following this SO POST: https://stackoverflow.com/a/67574280/16766691

Just go to package.json under your project root folder,

replace

"browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }

with

  "browserslist": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ]

And then recompile your project.

fhydralisk
  • 11
  • 3
1

Had the same problem after updates, underscore separator in numbers raised this same error ("Module parse failed: Identifier directly after number").

It was due to Babel, the issue was solved by adding the @babel/plugin-proposal-numeric-separator plugin.

Eino Gourdin
  • 4,169
  • 3
  • 39
  • 67
  • This solved the problem for me. Just thought I'd add, I am using webpack 4, so also had to add this to add this to my webpack config: ```module: { rules: [ { options: { plugins: [ '@babel/plugin-proposal-numeric-separator',``` – aggregate1166877 Mar 31 '23 at 01:38
0

If I had to take a guess, I’d say REMOVE node_modules & package-lock.json or yarn.lock THEN yarn AGAIN.

Sometimes upgrade module will cause unknown error.

YuTing
  • 6,555
  • 2
  • 6
  • 16
  • 1
    I tried this the first time, but it does not work. – RayAlto Aug 24 '21 at 09:04
  • Oh no, if the problem still bothering you and no one give a proper answer. Maybe you should try open an issue in [rehype-katex](https://github.com/remarkjs/remark-math/issues) – YuTing Aug 24 '21 at 09:30