wub / preact-cli-plugin-typescript

Adds TypeScript support to preact-cli :zap:
MIT License
49 stars 6 forks source link

Production build with ES6 classes causes errors from UglifyJS #2

Open slogsdon opened 7 years ago

slogsdon commented 7 years ago

Running preact build with the default tsconfig.json and preact.config.js files created by this plugin cause the following with a recently created Preact application (created with preact-cli):

[at-loader] Checking started in a separate process...

[at-loader] Ok, 0.732 sec.
0.chunk.32652.js from UglifyJs
Unexpected token: name (Profile) [./routes/profile/index.tsx:4,14][0.chunk.32652.js:20,6]
1.chunk.f5e4c.js from UglifyJs
Unexpected token: name (PostList) [./routes/posts/index.tsx:15,0][1.chunk.f5e4c.js:24,6]
2.chunk.d1976.js from UglifyJs
Unexpected token: name (Post) [./routes/post/index.tsx:15,14][2.chunk.d1976.js:12,6]
bundle.958ca.js from UglifyJs
Unexpected token: punc ()) [./components/app.tsx:12,43][bundle.958ca.js:913,165]
Build failed!

I got around the issue by adding the following to tsconfig.json:

 {
   "compileOnSave": false,
   "compilerOptions": {
     "target": "es2017",
     "module": "esnext",
     "moduleResolution": "node",
     "sourceMap": true,
     "jsx": "react",
     "jsxFactory": "h",
     "allowJs": false
+  },
+  "exclude": [
+    "node_modules"
+  ],
+  "awesomeTypescriptLoaderOptions": {
+    "useBabel": true,
+    "useCache": true
+  }
 }
slogsdon commented 7 years ago

I was working on including preact-async-route to leverage dynamic import, and it seems to also be resolved by changing the target to es5. Here's my current tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "allowJs": false,
    "jsx": "react",
    "jsxFactory": "h",
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "esnext",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "sourceMap": true,
    "strictNullChecks": true,
    "target": "es5"
  }
}
wub commented 7 years ago

Ah jeeze... thanks for this, not sure how this got through. I'll get onto it ASAP.

slogsdon commented 7 years ago

No worries from my end. Just wanted to log it in case it really needs to be fixed and/or someone else runs into this.

DevanB commented 6 years ago

Can confirm this still seems to be an issue and the fix, for me, was changing to:

target: "es5"

Thanks @slogsdon!