Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Uncaught TypeError when running production code locally after targeting ES2015 in tsconfig.json #346

Closed
@aurerua

Description

@aurerua

Is this a bug report?

Yes.

Can you also reproduce the problem with npm 4.x?

Yes.

Which terms did you search for in User Guide?

  • tsconfig.ts
  • compilerOptions

Environment

  1. npm ls react-scripts-ts (if you haven’t ejected): -
  2. node -v: v10.4.1
  3. npm -v: 6.1.0
  4. yarn --version (if you use Yarn):
  5. yarn ls react-scripts-ts (if you haven’t ejected): -

Then, specify:

  1. Operating system: Ubuntu 18.04 LTS
  2. Browser and version (if relevant): Google Chrome Version 67.0.3396.87 (Official Build) (64-bit)

Steps to Reproduce

(Write your steps here:)

  1. npx create-react-app my-app --scripts-version=react-scripts-ts
  2. cd my-app
  3. npm run eject
  4. npm run build
  5. cd build
  6. edit tsconfig.json and change the target value in compilerOptions to "ES2015"
  7. npx http-server
  8. In the browser run the page served by http-server and press CTRL-SHIFT-I to see the error message in the console.

Expected Behavior

No error in the console.

Actual Behavior

This error occurs in the browser's console:

Uncaught TypeError: Assignment to constant variable.
    at window.addEventListener (registerServiceWorker.ts:90)

I have found two ways to solve the problem:

  • do not change the target value in compilerOptions...
  • change line 37 in registerServiceWorker.ts from:
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;

to

let swUrl;
swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions