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.

Unexpected "You have illegal escape sequence..." in Chrome DevTools

See original GitHub issue

Current behavior:

I have got the error message saying

You have illegal escape sequence in your template literal, most likely inside content’s property value. Because you write your CSS inside a JavaScript string you actually have to do double escaping, so for example “content: ‘\00d7’;” should become “content: ‘\00d7’;”. You can read more about this here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#ES2018_revision_of_illegal_escape_sequences

While my one and only tsx file never contains a backslash.

import React from 'react'
import ReactDOM from 'react-dom'
import { css } from '@emotion/core'

const RED = 'red'

ReactDOM.render(
  <div
    css={css`
      color: ${RED};
    `}
  >
    Hey
  </div>,
  document.getElementById('root')
)

To reproduce:

  1. git clone https://github.com/ThisIsManta/parcel-ts-emotion
  2. yarn
  3. yarn start
  4. Open http://localhost:1234/ in Google Chrome (may possible to reproduce in other browsers as well)

Expected behavior:

Expect NOT to see the error message in Google console.

The error message will be gone if I put "resolutions": { "@emotion/serialize": "0.11.4" } in my package.json as the latest version of @emotion/core auto installs v0.11.5 which prints the error message unexpectedly.

image

Environment information:

  • I’m using Parcel + TS + Emotion via .babelrc
  • react version: 16.12.0
  • @emotion/core version: v10.0.27
  • See the rest in package.json
  • Chrome for Windows: 80.0.3987.87 (Official Build) (64-bit)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tills13commented, Jun 30, 2022

edit: for visibility, I’ve extracted this comment into a new issue: https://github.com/emotion-js/emotion/issues/2802

Apologies in advance for digging up an old issue.

I’m seeing this on a Next 12.2 project using their Emotion SWC compiler – just hoping to get some clarification before filing an issue with them. Can you briefly explain the logic behind these lines? Particularly in the context of sourceMap insertion?

Let’s say I have

const Element = styled.span`
  display: block;
`

Note how there’s no interpolation. This means the anon function in the linked lines should receive [['display: block']] as its arguments. With sourcemaps enabled, the function receives the sourcemap as the second arg (implying interpolation, not sure if that’s relevant).

args.length === 2 args[0][1] === undefined

Despite there being no escaping at all, I receive the error talked about in this issue.

~In all honesty, I really don’t see how that particular block of code checks for illegal escape sequences at all since escaped sequences (valid or not) don’t result in extra args.~

After further testing I realize there are some specific about escapes e.g.

> function x() { console.log([...arguments]) }
> x`content: '\00d7'`
[Arguments] { '0': [ undefined ] }
> x`content: '\\00d7'`
[Arguments] { '0': [ "content: '\\00d7'" ] }

which seems to support the logic of those lines.

I guess my question is, then, is this NextJS inserting the sourceMaps incorrectly or do those lines need a little extra logic to ignore the interpolated source map?

1reaction
Andaristcommented, Feb 12, 2020

As mentioned - I’m super busy right now. +1 comment is not really helpful in any way - if you care about the issue at hand I encourage you to just fix it and prepare a PR with the fix. If you don’t want to do that, please just wait patiently for the fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Illegal Escape Character "\" - java - Stack Overflow
The character '\' is a special character and needs to be escaped when used as part of a String, e.g., "\". Here is...
Read more >
Illegal escape sequence in your template literal - Get Help
I found a error in my console: “You have illegal escape sequence in your template literal, most likely inside content's property value.”…
Read more >
Tru64 UNIX - filibeto.org
For example, '\x777' is illegal. In addition, hexadecimal escape sequences with more than three characters provoke a warning if the error-checking compiler ...
Read more >
odporúča hrom Discover json invalid escape character in ...
Unexpected "You have illegal escape sequence..." in Chrome DevTools · Issue #1755 · emotion-js/emotion · GitHub. Help With Parsing a JSON String Containing ......
Read more >
curl.1 the man page
When using [] or {} sequences when invoked from a command line prompt, you probably have to put the full URL within double...
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