Skip to content

NXT-20659: Adapt ui and ss tests jobs to work with typescript - #403

Closed
alexandrumorariu wants to merge 3 commits into
feature/typescriptfrom
feature/NXT-20659
Closed

alexandrumorariu wants to merge 3 commits into
feature/typescriptfrom
feature/NXT-20659

Conversation

@alexandrumorariu

Copy link
Copy Markdown
Contributor

Checklist

  • I have read and understand the contribution guide
  • A CHANGELOG entry is included
  • I have run automated testing and it is passed
  • Documentation was added or is not needed
  • This is an API breaking change

Issue Resolved / Feature Added

enact pack does not work in a project that has a tsconfig.json and TypeScript 7 installed. Instead of failing, it exits with status 0 and writes no output at all, so the failure only shows up later in whatever called it.

Seen in @enact/ui-test-utils (start-tests), which builds an Enact framework bundle with enact pack --framework and then creates dist/framework/ilib:
Enact framework bundle... DONE
Build failed: ENOENT: no such file or directory, mkdir 'tests/screenshot/dist/framework/ilib'

There are two separate causes:

TypeScript 7 is not supported. When tsconfig.json exists, config/webpack.config.js enables in-build type checking (fork-ts-checker) and locates TypeScript with resolve.sync('typescript', {basedir: 'node_modules'}). That throws Cannot find module 'typescript' for TypeScript 7, because its package has no main entry. It would not help to fix the lookup alone: the root export of TypeScript 7 no longer exposes the classic JavaScript API (ts.createProgram, etc.) that fork-ts-checker is built on.
The error is swallowed. pack/serve call api(opts) inside a .then() callback. A synchronous throw while creating the webpack config rejects that outer promise, which nothing handles. bin/enact.js registers an uncaughtException handler that only logs the stack, so the process then exits with status 0. Callers that only check the exit code (and discard stderr when it is 0, as ui-test-utils does) see a successful build.

Resolution

config/webpack.config.js: added hasTypeScriptJsApi(). The ForkTsCheckerWebpackPlugin is only created when the installed TypeScript is older than 7. For TypeScript 7+ a one-line notice is printed and in-build type checking is skipped. Source files are still transpiled by Babel as before. If TypeScript is not installed at all, the existing Cannot find module 'typescript' error is still raised instead of being skipped.
commands/pack.js, commands/serve.js: api(opts) now runs inside the promise chain (Promise.resolve().then(() => api(opts)).catch(...)), so errors thrown while preparing the build are reported through the existing error handling and exit with status 1.
CHANGELOG.md: entries added under unreleased (pack, serve).
No dependency changes; package.json and npm-shrinkwrap.json are unchanged.

Additional Considerations

Behavior changes to be aware of

With TypeScript 7+, type errors are no longer reported during enact pack. They need to be caught by running tsc separately. With TypeScript < 7 nothing changes.
Errors thrown while preparing a build now cause a non-zero exit status. Setups that previously "passed" because of the swallowed error were not producing any output, but they will now fail visibly.

How to test

Create a project with a tsconfig.json and typescript@7 installed (for example npm install -D typescript@7) and run enact pack --framework --output dist/framework --externals-polyfill (or enact pack on a normal app).
Before: exit status 0, no dist folder, error only on stderr.
After: the build runs, prints TypeScript 7.x detected: skipping in-build type checking, and writes enact.js/enact.css.
Remove typescript from node_modules and run enact pack again. It should print Failed to compile. Cannot find module 'typescript' from 'node_modules' and exit with status 1.
With typescript@6, put a deliberate type error in a file under src/ and run enact pack --production. It should still fail with TS2322, as before.

Links

NXT-20659

Comments

Type checking under TypeScript 7 would need a different checker than fork-ts-checker. That is not part of this change, which only stops the build from failing.

dev and others added 3 commits October 5, 2026 16:12
…g a build

* Skip fork-ts-checker (in-build type checking) when TypeScript >= 7 is installed. TypeScript 7
  no longer provides the classic JavaScript API it needs, and has no `main` entry for `resolve`,
  so `resolve.sync('typescript')` threw "Cannot find module 'typescript'" whenever a project had
  a tsconfig.json.
* Run `api()` inside the promise chain in `pack` and `serve` so errors thrown synchronously while
  preparing the build are reported and exit non-zero. Previously they became an uncaught
  exception that bin/enact.js logs and swallows, so `enact pack` exited 0 without writing any
  output and callers saw only a confusing follow-on failure (e.g. ENOENT on the output folder).
@daniel-stoian-lgp

Copy link
Copy Markdown
Contributor

closing as duplicate of #401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants