From 39ed79ad3a7d298cc2fe8924da0f0bdf91047675 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Fri, 7 Aug 2026 17:37:53 -0400 Subject: [PATCH] fix(vite): use .mts config files and import.meta.dirname ## Current Behavior Vite 8.2 warns that these configs use features `configLoader: 'native'` cannot support: ESM syntax in a CommonJS-loaded `.ts` file, and `__dirname`. ## Expected Behavior No warning. `.mts` keeps configs ESM regardless of package.json `type`, and `import.meta.dirname` is the ESM equivalent of `__dirname`. ## Related Issue(s) NXC-4772 --- apps/api/{vite.config.ts => vite.config.mts} | 2 +- apps/shop/vite.config.mts | 2 +- packages/api/products/{vite.config.ts => vite.config.mts} | 2 +- packages/shared/models/{vite.config.ts => vite.config.mts} | 2 +- packages/shop/data/vite.config.mts | 2 +- packages/shop/feature-product-detail/vite.config.mts | 5 +++-- packages/shop/feature-products/vite.config.mts | 2 +- packages/shop/shared-ui/vite.config.mts | 2 +- vitest.config.ts => vitest.config.mts | 0 9 files changed, 10 insertions(+), 9 deletions(-) rename apps/api/{vite.config.ts => vite.config.mts} (95%) rename packages/api/products/{vite.config.ts => vite.config.mts} (95%) rename packages/shared/models/{vite.config.ts => vite.config.mts} (96%) rename vitest.config.ts => vitest.config.mts (100%) diff --git a/apps/api/vite.config.ts b/apps/api/vite.config.mts similarity index 95% rename from apps/api/vite.config.ts rename to apps/api/vite.config.mts index b87ca39..deb1353 100644 --- a/apps/api/vite.config.ts +++ b/apps/api/vite.config.mts @@ -3,7 +3,7 @@ import tsconfigPaths from 'vite-tsconfig-paths'; import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; export default defineConfig(() => ({ - root: __dirname, + root: import.meta.dirname, cacheDir: '../../node_modules/.vite/apps/api', plugins: [tsconfigPaths(), nxCopyAssetsPlugin(['*.md'])], test: { diff --git a/apps/shop/vite.config.mts b/apps/shop/vite.config.mts index 93403e2..fd3b1bc 100644 --- a/apps/shop/vite.config.mts +++ b/apps/shop/vite.config.mts @@ -5,7 +5,7 @@ import tsconfigPaths from 'vite-tsconfig-paths'; import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; export default defineConfig(() => ({ - root: __dirname, + root: import.meta.dirname, cacheDir: '../../node_modules/.vite/apps/shop', plugins: [angular(), tsconfigPaths(), nxCopyAssetsPlugin(['*.md'])], // Uncomment this if you are using workers. diff --git a/packages/api/products/vite.config.ts b/packages/api/products/vite.config.mts similarity index 95% rename from packages/api/products/vite.config.ts rename to packages/api/products/vite.config.mts index 696f5d2..aa97d9d 100644 --- a/packages/api/products/vite.config.ts +++ b/packages/api/products/vite.config.mts @@ -3,7 +3,7 @@ import tsconfigPaths from 'vite-tsconfig-paths'; import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; export default defineConfig(() => ({ - root: __dirname, + root: import.meta.dirname, cacheDir: '../../../node_modules/.vite/packages/api/products', plugins: [tsconfigPaths(), nxCopyAssetsPlugin(['*.md'])], test: { diff --git a/packages/shared/models/vite.config.ts b/packages/shared/models/vite.config.mts similarity index 96% rename from packages/shared/models/vite.config.ts rename to packages/shared/models/vite.config.mts index b2182df..26336f1 100644 --- a/packages/shared/models/vite.config.ts +++ b/packages/shared/models/vite.config.mts @@ -3,7 +3,7 @@ import tsconfigPaths from 'vite-tsconfig-paths'; import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; export default defineConfig(() => ({ - root: __dirname, + root: import.meta.dirname, cacheDir: '../../../node_modules/.vite/packages/shared/models', plugins: [tsconfigPaths(), nxCopyAssetsPlugin(['*.md'])], // Uncomment this if you are using workers. diff --git a/packages/shop/data/vite.config.mts b/packages/shop/data/vite.config.mts index d783d1f..f6cbaa7 100644 --- a/packages/shop/data/vite.config.mts +++ b/packages/shop/data/vite.config.mts @@ -5,7 +5,7 @@ import tsconfigPaths from 'vite-tsconfig-paths'; import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; export default defineConfig(() => ({ - root: __dirname, + root: import.meta.dirname, cacheDir: '../../../node_modules/.vite/packages/shop/data', plugins: [angular(), tsconfigPaths(), nxCopyAssetsPlugin(['*.md'])], // Uncomment this if you are using workers. diff --git a/packages/shop/feature-product-detail/vite.config.mts b/packages/shop/feature-product-detail/vite.config.mts index 53ca28e..18cc403 100644 --- a/packages/shop/feature-product-detail/vite.config.mts +++ b/packages/shop/feature-product-detail/vite.config.mts @@ -5,7 +5,7 @@ import tsconfigPaths from 'vite-tsconfig-paths'; import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; export default defineConfig(() => ({ - root: __dirname, + root: import.meta.dirname, cacheDir: '../../../node_modules/.vite/packages/shop/feature-product-detail', plugins: [angular(), tsconfigPaths(), nxCopyAssetsPlugin(['*.md'])], // Uncomment this if you are using workers. @@ -21,7 +21,8 @@ export default defineConfig(() => ({ setupFiles: ['src/test-setup.ts'], reporters: ['default'], coverage: { - reportsDirectory: '../../../coverage/packages/shop/feature-product-detail', + reportsDirectory: + '../../../coverage/packages/shop/feature-product-detail', provider: 'v8' as const, }, }, diff --git a/packages/shop/feature-products/vite.config.mts b/packages/shop/feature-products/vite.config.mts index fed9b14..5b1134f 100644 --- a/packages/shop/feature-products/vite.config.mts +++ b/packages/shop/feature-products/vite.config.mts @@ -5,7 +5,7 @@ import tsconfigPaths from 'vite-tsconfig-paths'; import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; export default defineConfig(() => ({ - root: __dirname, + root: import.meta.dirname, cacheDir: '../../../node_modules/.vite/packages/shop/feature-products', plugins: [angular(), tsconfigPaths(), nxCopyAssetsPlugin(['*.md'])], // Uncomment this if you are using workers. diff --git a/packages/shop/shared-ui/vite.config.mts b/packages/shop/shared-ui/vite.config.mts index 79c93df..3ff372e 100644 --- a/packages/shop/shared-ui/vite.config.mts +++ b/packages/shop/shared-ui/vite.config.mts @@ -5,7 +5,7 @@ import tsconfigPaths from 'vite-tsconfig-paths'; import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin'; export default defineConfig(() => ({ - root: __dirname, + root: import.meta.dirname, cacheDir: '../../../node_modules/.vite/packages/shop/shared-ui', plugins: [angular(), tsconfigPaths(), nxCopyAssetsPlugin(['*.md'])], // Uncomment this if you are using workers. diff --git a/vitest.config.ts b/vitest.config.mts similarity index 100% rename from vitest.config.ts rename to vitest.config.mts