question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@babel/parser throw an error when parsing object shorthand property async get () after updating to version 7.11.1

See original GitHub issue

index.js

export default {
  async get () {}
};

package.json

{
  "name": "babel-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {},
  "devDependencies": {
    "@babel/cli": "^7.10.5",
    "@babel/core": "^7.10.3"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "babel": "babel index.js"
  },
  "author": "",
  "license": "ISC"
}

when running npm run babel, I got an error below

{ SyntaxError: /Users/icefox/Desktop/babel-test/index.js: Unexpected token (2:11)

  1 | export default {
> 2 |   async get () {}
    |             ^
  3 | };
    at Parser._raise (/Users/icefox/Desktop/babel-test/node_modules/_@babel_parser@7.11.1@@babel/parser/lib/index.js:763:17)
    at Parser.raiseWithData (/Users/icefox/Desktop/babel-test/node_modules/_@babel_parser@7.11.1@@babel/parser/lib/index.js:756:17)
    at Parser.raise (/Users/icefox/Desktop/babel-test/node_modules/_@babel_parser@7.11.1@@babel/parser/lib/index.js:750:17)
    at Parser.unexpected (/Users/icefox/Desktop/babel-test/node_modules/_@babel_parser@7.11.1@@babel/parser/lib/index.js:8930:16)
    at Parser.parseIdentifierName (/Users/icefox/Desktop/babel-test/node_modules/_@babel_parser@7.11.1@@babel/parser/lib/index.js:11017:18)
    at Parser.parseIdentifier (/Users/icefox/Desktop/babel-test/node_modules/_@babel_parser@7.11.1@@babel/parser/lib/index.js:10994:23)
    at Parser.parseMaybePrivateName (/Users/icefox/Desktop/babel-test/node_modules/_@babel_parser@7.11.1@@babel/parser/lib/index.js:10311:19)
    at Parser.parsePropertyName (/Users/icefox/Desktop/babel-test/node_modules/_@babel_parser@7.11.1@@babel/parser/lib/index.js:10795:155)
    at Parser.parsePropertyDefinition (/Users/icefox/Desktop/babel-test/node_modules/_@babel_parser@7.11.1@@babel/parser/lib/index.js:10708:14)
    at Parser.parseObjectLike (/Users/icefox/Desktop/babel-test/node_modules/_@babel_parser@7.11.1@@babel/parser/lib/index.js:10612:25)
  loc: Position { line: 2, column: 11 },
  pos: 28,
  code: 'BABEL_PARSE_ERROR' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! babel-test@1.0.0 babel: `babel index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the babel-test@1.0.0 babel script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/icefox/.tnpm/_logs/2020-08-05T05_53_09_257Z-debug.log
[tnpm] subprocess:/Users/icefox/.nvm/versions/node/v10.21.0/lib/node_modules/tnpm/lib/npm_child_process.js exit code: 1, signal: null
[tnpm] mainprocess exit code: 1

It works fine with async with property name except get, and older version of @babel/parser, and in latest chrome and node v8, it turns out a valid syntax

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:13
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
JLHwungcommented, Aug 5, 2020

Fixed in @babel/parser 7.11.2.

npm update @babel/parser --depth 999

If you use yarn, you can either manually remove @babel/parser entries in yarn.lock and re-run yarn install or use yarn-deduplicate

# pick up 7.11.2, don't worry it will be removed later
yarn add @babel/parser
# yarn-deduplicate will resolve @babel/parser: ^7.11.1 to 7.11.2
yarn-deduplicate --packages @babel/parser yarn.lock
# remove `@babel/parser` from your package.json, it will be still in your node_modules
yarn remove @babel/parser 
7reactions
tomstumshaiscommented, Aug 5, 2020

For temporary fix right now we are using this one:

"resolutions": {
  "@babel/core/@babel/parser": "7.11.0"
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/parser/CHANGELOG.md - UNPKG
The CDN for @babel/parser. ... now correctly throws an error when there is a semicolon after the decorator: ... 248, export default async...
Read more >
babel/parser - NPM Package Versions - Socket.dev
Start using Socket to analyze @babel/parser and its 0 dependencies to secure your ... #15163 fix: Throw error when compiling super() in arrow...
Read more >
babel/parser
The Babel parser (previously Babylon) is a JavaScript parser used in Babel. The latest ECMAScript version enabled by default (ES2020). Comment attachment.
Read more >
@babel/runtime: Versions | Openbase
#14557 Fix parsing of < after object literals with the jsx plugin (@JLHwung) ... #13410 fix: throw when async() call param is object...
Read more >
Babel throwing errors on async/await syntax despite having ...
package.json. { "dependencies": { "babel-cli": "^6.18.0", "babel-plugin-transform-class-properties": "^6.18.0", ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found