I am converting a project over from using gulp to using nodemon so that I can use ES6 with babel. I'm following a pretty simple procedure to do so, which is well described here. A quick look at my package.json:
{
"main": "index.js",
"scripts": {
"start": "FORCE_COLOR=3 nodemon --exec babel-node index.js"
},
"dependencies": {
"deps": "1.1.1"
},
"devDependencies": {
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.5",
"@babel/node": "^7.16.5",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.16.5",
"nodemon": "^2.0.15"
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
}
When I run npm start
, nodemon runs the app, and reruns on save, but it crashes with a syntax error:
[nodemon] starting `babel-node index.js`
[HPM] Proxy created: /auth -> http://localhost:8081/
/myproject/node_modules/@babel/core/lib/parser/index.js:93
throw err;
^
SyntaxError: Legacy octal literals are not allowed in strict mode. (38:46)
at Parser._raise (/myproject/node_modules/@babel/parser/src/parser/error.js:147:45)
at Parser.raiseWithData (/myproject/node_modules/@babel/parser/src/parser/error.js:142:17)
at Parser.raise (/myproject/node_modules/@babel/parser/src/parser/error.js:91:17)
at Parser.recordStrictModeErrors (/myproject/node_modules/@babel/parser/src/tokenizer/index.js:1444:12)
at Parser.readNumber (/myproject/node_modules/@babel/parser/src/tokenizer/index.js:1239:12)
at Parser.getTokenFromCode (/myproject/node_modules/@babel/parser/src/tokenizer/index.js:951:14)
at Parser.nextToken (/myproject/node_modules/@babel/parser/src/tokenizer/index.js:307:10)
at Parser.next (/myproject/node_modules/@babel/parser/src/tokenizer/index.js:169:10) {
loc: Position { line: 38, column: 46 },
pos: 933,
code: 'BABEL_PARSE_ERROR',
reasonCode: 'StrictOctalLiteral'
}
[nodemon] app crashed - waiting for file changes before starting...
There doesn't seem to be a stack trace to the place in my code where this error is happening. I managed to track it down with some careful understanding of the no octal error, but other errors that come up look very similar, with no stack trace to the place in my own code where the error occurs. How can I debug like that? Is there a way to configure babel to include the origin of the error from my code?
Running babel-node
with Node 16.9 seems to fix this.
With Node 12 to 16.8:
SyntaxError: Legacy octal literals are not allowed in strict mode. (1:4)
at Parser._raise (/tmp/babel-test-3/node_modules/@babel/parser/lib/index.js:569:17)
With Node 16.9+:
SyntaxError: /tmp/babel-test-3/index2.js: Legacy octal literals are not allowed in strict mode. (1:4)
> 1 | a = 01;
| ^
2 |
at Parser._raise (/tmp/babel-test-3/node_modules/@babel/parser/lib/index.js:569:17)
No other changes were required.