POSTS / Do not rashly use angle brackets instead of Chinese guillemet in Markdown

Published: 2024-01-16

I just fixed a bug while trying to this blog show more in different categories:

As #20 says, this blog was deployed with Hakuba on Vercel. It was a small update which just using regex match instead of string comparison, but after it fetched everything the deploy process always down with one error:

error during build:
TypeError: Cannot read properties of undefined (reading 'paths')
    at create_builder (file:///vercel/path0/node_modules/@sveltejs/kit/dist/chunks/index2.js:52:48)
    at adapt (file:///vercel/path0/node_modules/@sveltejs/kit/dist/chunks/index2.js:204:18)
    at Object.closeBundle (file:///vercel/path0/node_modules/@sveltejs/kit/dist/vite.js:3104:11)
    at async Promise.all (index 0)
    at async /vercel/path0/node_modules/rollup/dist/shared/rollup.js:23688:13
    at async catchUnfinishedHookActions (/vercel/path0/node_modules/rollup/dist/shared/rollup.js:23162:20)
    at async rollupInternal (/vercel/path0/node_modules/rollup/dist/shared/rollup.js:23677:5)
    at async doBuild (/vercel/path0/node_modules/vite/dist/node/chunks/dep-6e2fe41e.js:41710:24)
    at async build (/vercel/path0/node_modules/vite/dist/node/chunks/dep-6e2fe41e.js:41552:16)
    at async CAC.<anonymous> (/vercel/path0/node_modules/vite/dist/node/cli.js:738:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Command "yarn run build" exited with 1

The intent of this error report is so vague that I just can’t find out how to fix it. What’s even more troubling is that the local deployment went wrong with another error, too.

yarn run v1.22.21
$ ts-node .scripts/pre/index.ts && vite build && ts-node .scripts/post/index.ts
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for .../KGarden-Hakuba/.scripts/pre/index.ts
    at new NodeError (node:internal/errors:405:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:99:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:142:36)
    at defaultLoad (node:internal/modules/esm/load:115:20)
    at nextLoad (node:internal/modules/esm/hooks:832:28)
    at load (.../KGarden-Hakuba/node_modules/ts-node/dist/child/child-loader.js:19:122)
    at nextLoad (node:internal/modules/esm/hooks:832:28)
    at Hooks.load (node:internal/modules/esm/hooks:415:26)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:168:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:807:20) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Then the first thing I need to do is to finish a first local build process. Thanks to Internet, I found this page run TS scripts via ts-node directly then tried node --loader ts-node/esm .scripts/pre/index.ts instead of ts-node .scripts/pre/index.ts and it worked. (though I still don’t know why in vercel it works well)

Once I finished a pre-process script I got a list of articles in markdown then I tried npx vite build and finally got the same error with vercel.

Because the only change is that I use multiple categories so the next thing to check is that which category brings that error. I tried one category at once and then I locked in on one category which contains an article written in Chinese. Natrually I thought it was a language issue so I tried to set some env vars both in project and in article level, but all those were not working.

That failure made me think about some other ways to handle this issue. I tried delete all content in the only Chinese article and was surprised to found that the error disappeared! I then put a quickly binary search in the content and eventually find that it was a pair of angle brackets which break down the whole deploy process: it was treated as an HTML tag and everything went wrong.