Skip to content

Commit 4ea2987

Browse files
committed
fix: Convert babel plugin to CommonJS format for Playwright compatibility
- Renamed babel-plugin-stub-vue-imports.js to .cjs extension - Changed from ES module exports to CommonJS module.exports - Updated playwright.i18n.config.ts to use correct file path with __dirname - Added import.meta.url handling for ES module compatibility This fixes the module resolution errors when running pnpm collect-i18n
1 parent 6c5f17a commit 4ea2987

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

babel-plugin-stub-vue-imports.cjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = function(babel) {
2+
const { types: t } = babel;
3+
4+
return {
5+
visitor: {
6+
ImportDeclaration(path) {
7+
const source = path.node.source.value;
8+
9+
// Handle Vue files
10+
if (source.endsWith('.vue')) {
11+
const specifiers = path.node.specifiers;
12+
if (specifiers.length > 0 && specifiers[0].type === 'ImportDefaultSpecifier') {
13+
const name = specifiers[0].local.name;
14+
// Replace with a variable declaration
15+
path.replaceWith(
16+
t.variableDeclaration('const', [
17+
t.variableDeclarator(
18+
t.identifier(name),
19+
t.objectExpression([])
20+
)
21+
])
22+
);
23+
}
24+
}
25+
// Handle CSS files - just remove the import
26+
else if (source.endsWith('.css') || source.endsWith('.scss') || source.endsWith('.less')) {
27+
path.remove();
28+
}
29+
}
30+
}
31+
};
32+
};

babel-plugin-stub-vue.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

playwright.i18n.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { defineConfig } from '@playwright/test'
2+
import path from 'path'
3+
import { fileURLToPath } from 'url'
4+
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
26

37
const config: any = defineConfig({
48
testDir: './scripts',
@@ -22,7 +26,7 @@ const config: any = defineConfig({
2226
config['@playwright/test'] = {
2327
babelPlugins: [
2428
// Stub Vue and CSS imports first to prevent parsing errors
25-
['babel-plugin-stub-vue-imports'],
29+
[path.join(__dirname, 'babel-plugin-stub-vue-imports.cjs')],
2630
// Module resolver to handle @ alias
2731
[
2832
'babel-plugin-module-resolver',

0 commit comments

Comments
 (0)