4.x: DataTable fails: Error: Invalid data type. Data accepts either: DataTable || generator || Array || function #5641
Copy link
Copy link
Closed
Description
Found in my production project after the migration from 3.x to 4.x. It works well in 3.x
Maybe the bug has the same reason as #5632 and #5635.
You can reproduce it with the Quickstart project
mirao@rog:~/workspace/my$ codeceptjs run --verbose
***************************************
nodeInfo: 24.16.0
osInfo: Linux 6.17 Ubuntu 24.04.4 LTS 24.04.4 LTS (Noble Numbat)
cpuInfo: (16) x64 AMD Ryzen 7 9700X 8-Core Processor
chromeInfo: 149.0.7827.114
edgeInfo: "N/A"
firefoxInfo: 151.0.3
safariInfo: N/A
playwrightBrowsers: "chromium: 149.0.7827.55, firefox: 151.0, webkit: 26.5"
If you need more detailed info, just run this: npx codeceptjs info
***************************************
Error: Invalid data type. Data accepts either: DataTable || generator || Array || function
at DataTable (/home/mirao/workspace/my/node_modules/codeceptjs/lib/data/context.js:117:10)
at DataTable (/home/mirao/workspace/my/node_modules/codeceptjs/lib/data/context.js:117:10)
at DataTable (/home/mirao/workspace/my/tests/My_test.ts:9:1)
at Object.<anonymous> (/home/mirao/workspace/my/tests/My_test.ts:11:2)
at Module._compile (node:internal/modules/cjs/loader:1854:14)
at Object.transformer (/home/mirao/workspace/my/node_modules/tsx/dist/register-BOkp8V6j.cjs:9:3176)
at Module.load (node:internal/modules/cjs/loader:1577:32)
at Module._load (node:internal/modules/cjs/loader:1379:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
at Module.require (node:internal/modules/cjs/loader:1600:12)
Invalid data type. Data accepts either: DataTable || generator || Array || function
Error:
at DataTable (/home/mirao/workspace/my/node_modules/codeceptjs/lib/data/context.js:117:10)
at DataTable (/home/mirao/workspace/my/node_modules/codeceptjs/lib/data/context.js:117:10)
at DataTable (/home/mirao/workspace/my/tests/My_test.ts:9:1)
at Object.<anonymous> (/home/mirao/workspace/my/tests/My_test.ts:11:2)
at Module._compile (node:internal/modules/cjs/loader:1854:14)
at Object.transformer (/home/mirao/workspace/my/node_modules/tsx/dist/register-BOkp8V6j.cjs:9:3176)
at Module.load (node:internal/modules/cjs/loader:1577:32)
at Module._load (node:internal/modules/cjs/loader:1379:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
at Module.require (node:internal/modules/cjs/loader:1600:12)
tests/My_test.ts:
import { dataTable as DataTable } from 'codeceptjs';
Feature('My');
const cases = new DataTable(['input', 'expected']);
cases.add(['input1', 'expected1']);
cases.add(['input2', 'expected2']);
Data(cases).Scenario('test something', ({ I, current }) => {
I.say(`Input: ${current.input}, Expected: ${current.expected}`);
});codecept.conf.ts:
import { setHeadlessWhen, setCommonPlugins } from '@codeceptjs/configure';
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);
// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();
export const config: CodeceptJS.MainConfig = {
tests: './tests/*_test.ts',
output: './output',
helpers: {
Playwright: {
browser: 'chromium',
url: 'http://localhost',
show: true
}
},
include: {
I: './steps_file.ts'
},
noGlobals: true,
plugins: {},
name: 'my',
require: ['tsx/cjs']
}tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM"],
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "bundler",
"strictNullChecks": false,
"types": ["codeceptjs", "node"],
"declaration": true,
"skipLibCheck": true
},
"exclude": ["node_modules"]
}Used SW:
- CodeceptJS 4.0.7
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
mirao commentedon Jun 16, 2026
AI suggests this fix:
mirao commentedon Jun 18, 2026
The bug was fixed by #5640 (4.1.0 beta 1), but there is one more issue
SyntaxError: Unexpected token (1:3)then. I hit the issue also in 4.0 when I solved #5641 by a patch.test:
output:
fix(data): detect DataTable structurally so Data() works under tsx/cjs (
mirao commentedon Aug 6, 2026
Reported as #5679