Projects Using art-template which depends on acorn Encounter Invalid Unicode Escape Character Errors in Windows

32 views Asked by At

I have been using art-template as a template engine for my project, but I recently encountered an issue that prevents the project from compiling correctly on Windows.

I've created a simple example to reproduce the problem, and the steps are straightforward:

  1. Environment Details:
  • Operating System: Windows 10 or 11
  • Node.js Version: v14,v16, v18, v20
  1. Create an empty project, and add the following to your package.json:
{
  "name": "acorn-invalid-unicode-escape-sequence",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "art-template": "4.13.0"
  }
}
  1. Install the dependencies:
yarn install # or npm install
  1. Run the following code in your console, and you'll see an error:
node -e "require('art-template/lib/precompile.js')"

You will then see the following exception:

Error Screenshot

Note: Why is it dependent on art-template/lib/precompile.js rather than acorn? Because directly depending on acorn does not produce an error.

After some basic debugging, I found the issue within the node:inspect/modules/cjs/loader Module._extensions['.js'] method:

Debug Screenshot

The fs.readFileSync(filename, 'utf8') call returns incorrect file content, and everything following \uff21-\uf is filled with blanks, causing a JavaScript runtime error. This is likely a bug in the fs module. Is there anyone who can help resolve this issue? Thank you very much!

0

There are 0 answers