This repository has been archived by the owner on Jan 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 492
Uncaught TypeError when running production code locally after targeting ES2015 in tsconfig.json #346
Comments
Same here. This seems to be an open UglifyJS bug: mishoo/UglifyJS#2842. Another workaround is to rename 'swUrl' in line 37. |
I got the same error and also resolved it with: src/registerServiceWorker.ts#L37: window.addEventListener('load', () => {
- const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
+ let swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; I dug a little deeper into the built source only to find that somehow with all the garbage that transpilers throw into the mix the production build transpiled this file into the following junk: build/static/js/main.<hash>.js formatted: L26143: function(t, e, n) {
"use strict";
Object.defineProperty(e, "__esModule", {
value: !0
});
const r = Boolean("localhost" === window.location.hostname || "[::1]" === window.location.hostname || window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));
function i(t) {
navigator.serviceWorker.register(t).then(t=>{
t.onupdatefound = (()=>{
const e = t.installing;
e && (e.onstatechange = (()=>{
"installed" === e.state && (navigator.serviceWorker.controller ? console.log("New content is available; please refresh.") : console.log("Content is cached for offline use."))
}
))
}
)
}
).catch(t=>{
console.error("Error during service worker registration:", t)
}
)
}
e.default = function() {
if ("serviceWorker"in navigator) {
if (new URL("",window.location.toString()).origin !== window.location.origin)
return;
window.addEventListener("load", ()=>{
const t = "/service-worker.js";
r ? (t = t,
fetch(t).then(e=>{
404 === e.status || -1 === e.headers.get("content-type").indexOf("javascript") ? navigator.serviceWorker.ready.then(t=>{
t.unregister().then(()=>{
window.location.reload()
}
)
}
) : i(t)
}
).catch(()=>{
console.log("No internet connection found. App is running in offline mode.")
}
),
navigator.serviceWorker.ready.then(()=>{
console.log("This web app is being served cache-first by a service worker. To learn more, visit https://goo.gl/SC7cgQ")
}
)) : i(t)
}
)
}
var t
}
,
e.unregister = function() {
"serviceWorker"in navigator && navigator.serviceWorker.ready.then(t=>{
t.unregister()
}
)
}
} Notice the mess around window.addEventListener about half way through. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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?
Environment
npm ls react-scripts-ts
(if you haven’t ejected): -node -v
: v10.4.1npm -v
: 6.1.0yarn --version
(if you use Yarn):yarn ls react-scripts-ts
(if you haven’t ejected): -Then, specify:
Steps to Reproduce
(Write your steps here:)
npx create-react-app my-app --scripts-version=react-scripts-ts
cd my-app
npm run eject
npm run build
cd build
tsconfig.json
and change thetarget
value incompilerOptions
to "ES2015"npx http-server
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:
I have found two ways to solve the problem:
target
value incompilerOptions
...registerServiceWorker.ts
from:to
Reproducible Demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
The text was updated successfully, but these errors were encountered: