SyntaxError Octal escape sequences are not allowed in strict mode.

I have a path to a file system, but when I use ts-node, it throws an error. How should I rewrite this so that I can get the file to work? Relevant Potion of code:
const DATAPATH = "C:\path\to\repo\advent-of-code\2022\01\data.txt";

const data = readFileSync(DATAPATH, "utf-8");
const DATAPATH = "C:\path\to\repo\advent-of-code\2022\01\data.txt";

const data = readFileSync(DATAPATH, "utf-8");
Error:
> ts-node ./lib/main.ts exec "-d" "2022-1"

C:\path\to\repo\advent-of-code\2022\01\runner.ts:10
const DATAPATH = `${"C:\path\to\repo\advent-of-code\2022\01\data.txt"}`;
^

SyntaxError: Octal escape sequences are not allowed in strict mode.
> ts-node ./lib/main.ts exec "-d" "2022-1"

C:\path\to\repo\advent-of-code\2022\01\runner.ts:10
const DATAPATH = `${"C:\path\to\repo\advent-of-code\2022\01\data.txt"}`;
^

SyntaxError: Octal escape sequences are not allowed in strict mode.
7 Replies
ErickO
ErickO2y ago
lmao probably need to escape it like \01 but you should prolly not make file paths like that
Jochem
Jochem2y ago
the quick and dirty fix is to switch to forward slashes, or use double back slashes
ErickO
ErickO2y ago
dirty indeed PepeLaugh
Jochem
Jochem2y ago
or honestly, just don't use a template literal, there's no reason to in this example
Lofty!
Lofty!2y ago
I tried without, same issue actually...
Jochem
Jochem2y ago
hm, then quick and dirty is forward slashes or double back slashes, more thorough is using something like this https://nodejs.org/api/path.html
Lofty!
Lofty!2y ago
Done, thanks!
Want results from more Discord servers?
Add your server