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.

SyntaxError: Expected atom at position 2 \p{Script_Ex

See original GitHub issue

Bug Report

Current Behavior

> babel . --out-dir dist

SyntaxError: Expected atom at position 2
    \p{Script_Ex
      ^
    at bail (/home/shm/dpp-query-ws/node_modules/regjsparser/parser.js:1093:13)
    at parseTerm (/home/shm/dpp-query-ws/node_modules/regjsparser/parser.js:486:9)
    at parseAlternative (/home/shm/dpp-query-ws/node_modules/regjsparser/parser.js:457:21)
    at parseDisjunction (/home/shm/dpp-query-ws/node_modules/regjsparser/parser.js:437:16)
    at parse (/home/shm/dpp-query-ws/node_modules/regjsparser/parser.js:1108:18)
    at rewritePattern (/home/shm/dpp-query-ws/node_modules/regexpu-core/rewrite-pattern.js:324:15)
    at PluginPass.RegExpLiteral (/home/shm/dpp-query-ws/node_modules/@babel/plugin-transform-unicode-regex/lib/index.js:50:51)
    at newFn (/home/shm/dpp-query-ws/node_modules/@babel/traverse/lib/visitors.js:193:21)
    at NodePath._call (/home/shm/dpp-query-ws/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/home/shm/dpp-query-ws/node_modules/@babel/traverse/lib/path/context.js:40:17)

Input Code

  • REPL or Repo link if applicable:
var your => (code) => here;

Expected behavior/code Successful transpiled code

Babel Configuration (.babelrc, package.json, cli command) package.json

"devDependencies": {
    "@babel/cli": "^7.1.2",
    "@babel/core": "^7.1.2",
    "@babel/node": "^7.0.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
    "@babel/preset-env": "^7.1.0",
    "@babel/preset-flow": "^7.0.0",
    "nodemon": "^1.18.4"
  }

babel.config.js

module.exports = {
  "presets": ["@babel/preset-env","@babel/preset-flow"],
  "plugins": [
    "@babel/plugin-proposal-object-rest-spread"
  ]
}

Environment

  • Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34]
  • Node/npm version: Node 8.12.0/npm 6.4.1
  • OS: Ubuntu 16.04.4 LTS
  • Monorepo
  • How you are using Babel: [e.g. cli, register, loader] cli
    "build": "babel . --out-dir dist"
    

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
jasonkcommented, Jun 28, 2019

So I’ve managed to narrow this down. I’m not certain what the “real” fix for it is, but I have some ideas, (and a workaround that is working for me )…

TL;DR - Workaround:

[ '@babel/preset-env', {
  include : [ '@babel/plugin-proposal-unicode-property-regex' ],
  exclude : [ '@babel/plugin-transform-unicode-regex' ],
} ],

When it fails for me there are two unicode regex related plugins that have been enabled by preset-env: transform-unicode-regex and proposal-unicode-property-regex. They are both doing effectively the exact same thing, using rewritePattern from regexpu-core to transform the regex into an equivalent ES5 regex.

However, only proposal-unicode-property-regex is passing the option unicodePropertyEscape: true when it calls rewritePattern, transform-unicode-regex is not, which causes regjsparser to choke on \p{...} and \P{...} patterns.

Unfortunately I don’t understand the Babel internals well enough to determine:

  • Why preset-env decided that both of these plugins were needed when the only difference between them is that one of them understands \p/\P and the other doesn’t.
  • How it determines what order to apply the plugins in. Even though they are nearly identical, it seems as though it would work fine if proposal-unicode-property-regex were applied first, since it would transform the problematic escapes into something that transform-unicode-regex wouldn’t have issues with.

If it helps, here is my preset-env debug output:

@babel/preset-env: `DEBUG` option

Using targets:
{
  "android": "67",
  "chrome": "72",
  "edge": "15",
  "firefox": "60",
  "ie": "11",
  "ios": "11",
  "opera": "46",
  "safari": "11",
  "samsung": "6.2"
}

Using modules transform: false

Using plugins:
  transform-template-literals { "android":"67", "ie":"11", "ios":"11", "safari":"11" }
  transform-literals { "android":"67", "ie":"11" }
  transform-function-name { "android":"67", "edge":"15", "ie":"11" }
  transform-arrow-functions { "android":"67", "ie":"11" }
  transform-block-scoped-functions { "android":"67" }
  transform-classes { "android":"67", "ie":"11" }
  transform-object-super { "android":"67", "ie":"11" }
  transform-shorthand-properties { "android":"67", "ie":"11" }
  transform-duplicate-keys { "android":"67", "ie":"11" }
  transform-computed-properties { "android":"67", "ie":"11" }
  transform-for-of { "android":"67", "ie":"11" }
  transform-sticky-regex { "android":"67", "ie":"11" }
  transform-dotall-regex { "android":"67", "edge":"15", "firefox":"60", "ie":"11", "ios":"11", "opera":"46", "safari":"11", "samsung":"6.2" }
  transform-unicode-regex { "android":"67", "ie":"11", "ios":"11", "safari":"11" }
  transform-spread { "android":"67", "ie":"11" }
  transform-parameters { "android":"67", "edge":"15", "ie":"11" }
  transform-destructuring { "android":"67", "ie":"11" }
  transform-block-scoping { "android":"67", "ie":"11" }
  transform-typeof-symbol { "android":"67", "ie":"11" }
  transform-new-target { "android":"67", "ie":"11" }
  transform-regenerator { "android":"67", "ie":"11" }
  transform-exponentiation-operator { "android":"67", "ie":"11" }
  transform-async-to-generator { "android":"67", "ie":"11" }
  proposal-async-generator-functions { "android":"67", "edge":"15", "ie":"11", "ios":"11", "opera":"46", "safari":"11", "samsung":"6.2" }
  proposal-object-rest-spread { "android":"67", "edge":"15", "ie":"11", "ios":"11", "opera":"46", "safari":"11", "samsung":"6.2" }
  proposal-unicode-property-regex { "android":"67", "edge":"15", "firefox":"60", "ie":"11", "ios":"11", "opera":"46", "safari":"11", "samsung":"6.2" }
  proposal-json-strings { "android":"67", "edge":"15", "firefox":"60", "ie":"11", "ios":"11", "opera":"46", "safari":"11", "samsung":"6.2" }
  proposal-optional-catch-binding { "android":"67", "edge":"15", "ie":"11", "ios":"11", "opera":"46", "safari":"11", "samsung":"6.2" }
  transform-named-capturing-groups-regex { "android":"67", "edge":"15", "firefox":"60", "ie":"11", "ios":"11", "opera":"46", "safari":"11", "samsung":"6.2" }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Mathias Bynens on Twitter: "@FakeUnicode @AKermodeBear ...
SyntaxError: Expected atom at position 2 \p{Script_Ex · Issue #8951 · babel/babel. Bug Report Current Behavior > babel .
Read more >
Facing Expected atom at position error in regular expression
Expected atom at position 37 A-Za-z]*\p{L}. I tried using npm install --save-dev @babel/plugin-proposal-unicode-property-regex and
Read more >
Facing Expected atom at position error in regular expression ...
Coding example for the question Facing Expected atom at position error in regular expression-babel.js.
Read more >
Angular 13: running Storybook 6.4 fails with ModuleBuildError
I use Storybook with Compodoc and have Eslint for TypeScript in place. ... /Users/xxx/node_modules/prettier/standalone.js: Expected atom at position 0 ERR!
Read more >
CoffeeScript
Major new features in CoffeeScript 2 include async functions and JSX. ... and a .babelrc file (or other equivalent) in place, you can...
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