ember-cli-typescript: Type errors crash the build on Ember CLI 3.15+

Edit by @chriskrycho:* original title was “Does not appear to work with Ember 3.27”. Updated to reflect the actual underlying issue in Ember CLI.

Please paste the output of ember -v here

❯ ember -v
ember-cli: 3.27.0
node: 12.20.2
os: linux x64

Please paste the output of tsc -v here

❯ yarn tsc -v

Version 4.3.5

Please paste the version of ember-cli-typescript and ember-cli-typescript-blueprints here

4.2.1 blueprints package removed

Please paste your tsconfig.json and tslint.json or eslint.json (if applicable) below

default w/ 4.2.1

What are instructions we can follow to reproduce the issue?

Repro is these changes: https://github.com/NullVoxPopuli/ember-play/pull/5/commits/8dcf53e06fd9f40182dd29e0a99aeb8fe8e5a94b

git clone git@github.com:NullVoxPopuli/ember-play.git
git checkout 8dcf53e06fd9f40182dd29e0a99aeb8fe8e5a94b
yarn
ember s
# error! (ember-cli crashes)

Inverse reproduction (fix?): Remove ember-cli-typescript: https://github.com/NullVoxPopuli/ember-play/pull/5/commits/689c0ee0777c6e57e9714f319f8f04bb8c356c63

  • Downside: no more type checking working in ember-cli terminal

Now about that bug. What did you expect to see?

This is a WIP PR / Library, but, I expect to still be able to run /tests while I iterate on implementation and not have to continually restart ec-ts whenever there is an error.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I went hunting and it looks like the situation is pretty much what I was speculating above. I spun up fresh app with an in-repo addon that returns Promise.reject('uh oh') from postBuild() after each even-numbered (re)build.

Here’s the output for an initial build and three subsequent rebuilds (so in total, success -> fail -> success -> fail):

ember-cli@3.14.0, Node 12/16
$ ember serve

Build successful (3376ms) – Serving on http://localhost:7020/

Slowest Nodes (totalTime >= 5%)                                                                                             | Total (avg)
----------------------------------------------------------------------------------------------------------------------------+------------------------------------
BroccoliRollup (6)                                                                                                          | 693ms (115 ms)
Bundler (1)                                                                                                                 | 660ms
Babel: @ember/test-helpers (1)                                                                                              | 395ms
Package /assets/vendor.js (1)                                                                                               | 299ms
Babel: ember-source (5)                                                                                                     | 254ms (50 ms)
ember-auto-import-analyzer (4)                                                                                              | 216ms (54 ms)

file changed templates/application.hbs
file changed templates/application.hbs
uh oh

file changed templates/application.hbs

Build successful (232ms) – Serving on http://localhost:7020/

Slowest Nodes (totalTime >= 5%)                                                                                             | Total (avg)
----------------------------------------------------------------------------------------------------------------------------+------------------------------------
Babel: ember-source (5)                                                                                                     | 33ms (6 ms)
ember.js (1)                                                                                                                | 30ms
BroccoliMergeTrees (22)                                                                                                     | 27ms (1 ms)
Funnel (60)                                                                                                                 | 22ms (0 ms)

file changed templates/application.hbs
uh oh
ember-cli@3.15.0-beta.1, Node 12
$ ember serve                                                                                                                                                                                                                 

Build successful (3573ms) – Serving on http://localhost:7020/

Slowest Nodes (totalTime >= 5%)                                                                                             | Total (avg)
----------------------------------------------------------------------------------------------------------------------------+------------------------------------
Bundler (1)                                                                                                                 | 777ms
BroccoliRollup (6)                                                                                                          | 680ms (113 ms)
Babel: @ember/test-helpers (1)                                                                                              | 379ms
Package /assets/vendor.js (1)                                                                                               | 337ms
Babel: ember-source (5)                                                                                                     | 284ms (56 ms)
ember-auto-import-analyzer (4)                                                                                              | 207ms (51 ms)

file changed templates/application.hbs
(node:22890) UnhandledPromiseRejectionWarning: uh oh
(Use `node --trace-warnings ...` to show where the warning was created)
(node:22890) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:22890) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
file changed templates/application.hbs

Build successful (229ms) – Serving on http://localhost:7020/

Slowest Nodes (totalTime >= 5%)                                                                                             | Total (avg)
----------------------------------------------------------------------------------------------------------------------------+------------------------------------
Babel: ember-source (5)                                                                                                     | 35ms (7 ms)
ember.js (1)                                                                                                                | 30ms
BroccoliMergeTrees (22)                                                                                                     | 27ms (1 ms)
Funnel (60)                                                                                                                 | 23ms (0 ms)

file changed templates/application.hbs
(node:22890) UnhandledPromiseRejectionWarning: uh oh
(node:22890) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)
ember-cli@3.15.0-beta.1, Node 16
$ ember serve                                                                                                                                                                                                                 WARNING: Node v16.4.2 is not tested against Ember CLI on your platform. We recommend that you use the most-recent "Active LTS" version of Node.js. See https://git.io/v7S5n for details.

Build successful (3616ms) – Serving on http://localhost:7020/

Slowest Nodes (totalTime >= 5%)                                                                                             | Total (avg)
----------------------------------------------------------------------------------------------------------------------------+------------------------------------
BroccoliRollup (6)                                                                                                          | 729ms (121 ms)
Bundler (1)                                                                                                                 | 726ms
Babel: @ember/test-helpers (1)                                                                                              | 444ms
Package /assets/vendor.js (1)                                                                                               | 268ms
Babel: ember-source (5)                                                                                                     | 258ms (51 ms)
ember-auto-import-analyzer (4)                                                                                              | 221ms (55 ms)

file changed templates/application.hbs
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "uh oh".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Prior to 3.15, the CLI treated promise rejections in postBuild as failing the build, so in both older and newer versions of Node, everything works as expected.

Starting in 3.15, a promise returned from postBuild doesn’t get .catch()ed, meaning the rejection goes unhandled. In older versions of Node, this emits a warning (and seemingly still does fail the build, which is interesting), but in more recent Node versions, that unhandled rejection warning terminates the process.

Like I said above, given that ember-cli does wait for postBuild promises (i.e. it doesn’t just ignore the postBuild return value), it seems like a bug there that the rejection goes unhandled, and I think the behavior prior to 3.15 was correct.

For what it’s worth, our app & addons work with ember-source 3.27.5 & latest ember-cli-typescript. So I do not think it is a general issue, but probably some combination of another addon or so.

I think we got the confusion sorted out in Discord, but for anyone else reading along in this thread: noEmitOnError is a TypeScript configuration option (not something we invented!) that means “do not emit transpiled code when there’s a type error.”