2 years ago
#70269
Hyejung
SyntaxError: Unexpected keyword 'const'
I installed babel packages as below.
package.json:
"dependencies": {
"@babel/preset-react": "^7.16.7",
"@prisma/client": "^3.8.1",
"apollo-server": "^3.6.2",
"graphql": "^16.2.0"
},
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.16.8",
"babel-preset-react": "^6.24.1",
"nodemon": "^2.0.15",
"prisma": "^3.8.1"
}
and I made babel.config.json file.
babel.config.json:
{
"presets": ["@babel/preset-env"]
}
I did the same as babel Node
API should be done according to official doc:https://babeljs.io/setup#installation
But I got the error message:
SyntaxError: /Users/hayat/Desktop/chungchunon-backend/server.js: Unexpected keyword 'const'. (40:0)
38 |
39 |
> 40 | const server = new ApolloServer({
| ^
41 | typeDefs,
42 | resolvers,
43 | });
at Object._raise (/Users/hayat/Desktop/chungchunon-backend/node_modules/@babel/parser/lib/index.js:569:17)
at Object.raiseWithData (/Users/hayat/Desktop/chungchunon-backend/node_modules/@babel/parser/lib/index.js:562:17)
at Object.raise (/Users/hayat/Desktop/chungchunon-backend/node_modules/@babel/parser/lib/index.js:523:17)
at Object.checkReservedWord (/Users/hayat/Desktop/chungchunon-backend/node_modules/@babel/parser/lib/index.js:13044:12)
at Object.parseIdentifierName (/Users/hayat/Desktop/chungchunon-backend/node_modules/@babel/parser/lib/index.js:13005:12)
at Object.parseIdentifier (/Users/hayat/Desktop/chungchunon-backend/node_modules/@babel/parser/lib/index.js:12975:23)
at Object.parseBindingAtom (/Users/hayat/Desktop/chungchunon-backend/node_modules/@babel/parser/lib/index.js:11037:17)
at Object.parseVarId (/Users/hayat/Desktop/chungchunon-backend/node_modules/@babel/parser/lib/index.js:14216:20)
at Object.parseVar (/Users/hayat/Desktop/chungchunon-backend/node_modules/@babel/parser/lib/index.js:14192:12)
at Object.parseVarStatement (/Users/hayat/Desktop/chungchunon-backend/node_modules/@babel/parser/lib/index.js:14009:10) {
loc: Position { line: 40, column: 0 },
pos: 814,
code: 'BABEL_PARSE_ERROR',
reasonCode: 'UnexpectedKeyword'
}
It seems that due to the BABEL_PARSE_ERROR
, it can't read const
. But as I installed all necessary babel package, I can't understand why.
node.js
graphql
babeljs
prisma
0 Answers
Your Answer