.../articles/
An "Invalid Character" Error Broke Our Page in IE11 [Nuxt.js]

An "Invalid Character" Error Broke Our Page in IE11 [Nuxt.js]

2019.12.15

Table of Contents

  • Checked it in IE, the app was dead
  • Maybe it's a polyfill issue?
  • Digging through the package to find what to transpile
  • Conclusion: read the error carefully

Checked It in IE, the App Was Dead

Whenever you build an app or a site, you check it in IE, right? You brace yourself, wondering "will it actually display properly...?" and then sometimes it's like, "yep, sure enough, it's not showing up." This time, I was getting the following error.

Maybe It's a Polyfill Issue?

At times like this, you figure some ES6-era syntax probably isn't being transformed by Babel — maybe a missing config? — so you go check.

This time I was using Nuxt, which uses core-js@2 by default, so I figured the syntax I was using shouldn't be an issue — maybe it was a config mistake? I ended up endlessly fiddling with Babel options.

I spent a few hours setting debug: true and tracing through the logs.

    babel: {
      presets ({ isServer }, [preset, options]) {
        return [
          [
            preset,
            {
              ...options,
              targets: isServer
                ? { node: 'current' }
                : { browsers: ['last 2 versions'], ie: 11 },
              corejs: { version: 2 },
              debug: true,
            },
          ],
        ]
      },

While asking @ymmooot for advice, I got as far as figuring out that even though transform-template-literals was set to { "android":"76", "ie":"11", "opera":"12.1", "safari":"12.1" }, it was still being used in the built JS, which was why it was dying in IE. From there,

Yamamoto: "Maybe it's code in node_modules that Babel isn't touching~"

That was the advice I got, and I thought, wait, really? There's a pattern like that? So I went and looked into it.

Digging Through the Package to Find What to Transpile

So I went back to the original error message that had been showing all along.

Invalid character. 93~~~.js (1, 2453)

So I actually looked at the corresponding spot (line 1, character 2453) in the built file where the error was occurring, and found this part remaining:

innerHTML=`@keyframes ${t} {${n}}`

Looking at the browser support status for template literals, IE doesn't support them. "Ah, so that's it," I thought, and while looking at the reference article in *1, I added transpilation for it.

  build: {
    publicPath: '/assets/',
    extractCSS: true,
    transpile: [
      /(.+)(library-name\/src\/path\/)(.+)(\.js)$/,
    ],
    babel: {
      presets ({ isServer }, [preset, options]) {
        return [
          [
            preset,
            {
              ...options,
              targets: isServer
                ? { node: 'current' }
                : { browsers: ['last 2 versions', '> 0.25%, not dead'], ie: 11 },
              corejs: { version: 2 },
            },
          ],
        ]
      },
    },

With this fix in place, it now displays correctly in IE as well.

Conclusion: Read the Error Carefully

Looking at this whole sequence of events, I'm sure anyone experienced would find it pretty embarrassing. If I had just carefully read the error message from the start and checked the corresponding spot in the file where the error occurred, I probably could have debugged this right away. I'm someone who's always telling others to read error messages carefully, so I ended up throwing an enormous boomerang right back at myself, and I'm reflecting on that. I'll leave this as a cautionary tale of something I messed up, both as a bit of penance and as a lesson to myself.

References

written by

.../article/

Articles

All articles

From Firebase to Vercel, Contentful to microCMS — a migration log written with Claude Code

From Firebase to Vercel, Contentful to microCMS — a migration log written with Claude Code

We moved our corporate site's hosting and CMS, and made it bilingual along the way. The constraints we only found by running against real data were more useful than the migration itself, so this post focuses on where we got stuck.

Can't Read POST Data with Firebase Functions × Remix?

Can't Read POST Data with Firebase Functions × Remix?

How to read POST data from a Remix action when running on Firebase Functions.

Generative AI for Executives and Leaders: An Approach to Self-Driven DX

Generative AI for Executives and Leaders: An Approach to Self-Driven DX

Building a structure where executives and leaders themselves can identify issues and evaluate solutions using generative AI. We introduce how combining this with our hands-on support dramatically improves both the quality and speed of digital transformation.

Deploying a Monorepo Next.js App (App Router) to AWS Amplify

Deploying a Monorepo Next.js App (App Router) to AWS Amplify

Notes on the obstacles we hit while deploying a Next.js app managed in a monorepo to AWS Amplify.

Keeping Production Running Smoothly with Remote Work and Online Meetings [Documentation]

Keeping Production Running Smoothly with Remote Work and Online Meetings [Documentation]

Many production companies have adopted remote work as a result of the pandemic, and we are one of them.

Designing an E-Commerce Site That Sells: How to Find Great Reference Examples

Designing an E-Commerce Site That Sells: How to Find Great Reference Examples

There is no single formula for e-commerce design that sells. Driving revenue requires a solid concept, and getting to that concept requires thorough research.

Productivity Tools We Recommend as a Production Company, Including Services That Work Well Solo

Productivity Tools We Recommend as a Production Company, Including Services That Work Well Solo

With remote work becoming the norm during the COVID-19 pandemic, our team now works from home most days of the week.

We Released Thought Recorder, a Figma Plugin for Keeping a Commit History of Your Designs

We Released Thought Recorder, a Figma Plugin for Keeping a Commit History of Your Designs

We hope this helps web designers who work in Figma. Read on for how to use it.

How to Build an E-Commerce Site, and Which Platforms We Recommend

How to Build an E-Commerce Site, and Which Platforms We Recommend

Shopping online for fashion, appliances, and even groceries is now routine. With the pandemic accelerating the shift, we receive a steady stream of questions about which platform to use and how much it costs.

Generating FastAPI Schema Classes from OpenAPI

Generating FastAPI Schema Classes from OpenAPI

We chose FastAPI, a relatively modern framework, for a Python API project. FastAPI can generate an OpenAPI definition from your backend code, but here we do the opposite: generating FastAPI schema classes from an OpenAPI definition prepared in advance.

View all articles

Contact us