From 1f063320e24bc2597b78514dcd4a25360eda4180 Mon Sep 17 00:00:00 2001 From: Dan Ichim Date: Mon, 28 Sep 2026 13:00:53 +0300 Subject: [PATCH 1/2] fix error ts --- commands/pack.js | 20 ++++++++++++++------ config/webpack.config.js | 34 +++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/commands/pack.js b/commands/pack.js index cb937de1..18cb5fca 100755 --- a/commands/pack.js +++ b/commands/pack.js @@ -325,17 +325,25 @@ function cli (args) { if (opts.help) displayHelp(); process.chdir(app.context); - import('chalk').then(({default: _chalk}) => { - chalk = _chalk; - import('strip-ansi').then(({default: _stripAnsi}) => { + import('chalk') + .then(({default: _chalk}) => { + chalk = _chalk; + return import('strip-ansi'); + }) + .then(({default: _stripAnsi}) => { stripAnsi = _stripAnsi; - api(opts).catch(err => { + return api(opts); + }) + .catch(err => { + if (chalk) { printErrorDetails(err, () => { process.exit(1); }); - }); + } else { + console.error(err); + process.exit(1); + } }); - }); } module.exports = {api, cli}; diff --git a/config/webpack.config.js b/config/webpack.config.js index 18980f43..60d2d1d7 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -27,7 +27,6 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath'); const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin'); const NodePolyfillPlugin = require('node-polyfill-webpack-plugin'); -const resolve = require('resolve'); const TerserPlugin = require('terser-webpack-plugin'); const {DefinePlugin, EnvironmentPlugin} = require('webpack'); const { @@ -39,6 +38,27 @@ const { } = require('@enact/dev-utils'); const createEnvironmentHash = require('./createEnvironmentHash'); +// fork-ts-checker needs the classic TypeScript compiler API. TypeScript 7's +// package entry only exports a version, so resolution via `main` fails and the +// checker cannot run. Return null to skip it instead of failing the build. +function resolveLegacyTypeScript(context) { + let typescriptPath; + try { + typescriptPath = require.resolve('typescript', {paths: [context]}); + } catch (e) { + return null; + } + + try { + const typescript = require(typescriptPath); + if (typeof typescript.createProgram === 'function') return typescriptPath; + } catch (e) { + return null; + } + + return null; +} + // This is the production and development configuration. // It is focused on developer experience, fast rebuilds, and a minimal bundle. module.exports = function ( @@ -60,6 +80,12 @@ module.exports = function ( // Check if TypeScript is setup const useTypeScript = fs.existsSync('tsconfig.json'); + const typeScriptPath = useTypeScript ? resolveLegacyTypeScript(app.context) : null; + if (useTypeScript && !typeScriptPath) { + console.warn( + 'Skipping TypeScript type checking during the build. The installed "typescript" package does not provide the compiler API required by fork-ts-checker.' + ); + } // Check if Tailwind config exists const useTailwind = fs.existsSync(path.join(app.context, 'tailwind.config.js')); @@ -624,13 +650,11 @@ module.exports = function ( // and parses any to copy over any webOS meta assets at build time. new WebOSMetaPlugin({htmlPlugin: HtmlWebpackPlugin}), // TypeScript type checking - useTypeScript && + typeScriptPath && new ForkTsCheckerWebpackPlugin({ async: !isEnvProduction, typescript: { - typescriptPath: resolve.sync('typescript', { - basedir: 'node_modules' - }), + typescriptPath: typeScriptPath, configOverwrite: { compilerOptions: { sourceMap: shouldUseSourceMap, From 3bb9fc37b98d7860d96748ce8368c57c2de4911f Mon Sep 17 00:00:00 2001 From: Dan Ichim Date: Mon, 28 Sep 2026 15:59:03 +0300 Subject: [PATCH 2/2] fix lint --- config/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/webpack.config.js b/config/webpack.config.js index 60d2d1d7..351974ba 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -41,7 +41,7 @@ const createEnvironmentHash = require('./createEnvironmentHash'); // fork-ts-checker needs the classic TypeScript compiler API. TypeScript 7's // package entry only exports a version, so resolution via `main` fails and the // checker cannot run. Return null to skip it instead of failing the build. -function resolveLegacyTypeScript(context) { +function resolveLegacyTypeScript (context) { let typescriptPath; try { typescriptPath = require.resolve('typescript', {paths: [context]});