Fix TypeScript ESM module resolution docs - recommend tsx over ts-node/esm #5324
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation/Description of the PR
Documentation incorrectly recommended
ts-node/esmwithexperimentalSpecifierResolution: "node"for TypeScript ESM projects. This causes "Cannot find module" errors when importing page objects:Root cause:
experimentalSpecifierResolutionis deprecated and doesn't affect Node.js runtime.ts-node/esmdoesn't resolve extensionless imports and is incompatible with"type": "module".Fix: Recommend
tsx/cjswhich handles ESM correctly:Changes
Documentation:
lib/utils/loaderCheck.js: RemovedexperimentalSpecifierResolution, added ts-node/esm limitations warningdocs/typescript.md: Reordered to emphasize tsx, marked ts-node/esm as not recommendedTest case (
test/data/typescript-tsx-esm/):"type": "module"and extensionless importsCode cleanup:
lib/mocha/factory.js: Removed broken ESM fallback logicApplicable helpers:
Applicable plugins:
Type of change
Checklist:
npm run docs)npm run lint)npm test)Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
googlechromelabs.github.ionode install.mjs(dns block)https://storage.googleapis.com/chrome-for-testing-public/138.0.7204.168/linux64/chrome-headless-shell-linux64.zipnode install.mjs(http block)jsonplaceholder.typicode.comnode /home/REDACTED/work/CodeceptJS/CodeceptJS/node_modules/.bin/mocha test/unit --recursive --timeout 10000 --reporter @testomatio/reporter/mocha(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>CodeceptJS 4.x: The console's docs suggests "module": "ESNext", but can't import page object with such setting (Cannot find module)</issue_title>
<issue_description>config
codecept.conf.tstsconfig.json (as suggested by CodeceptJS if you run a test without any "require" in your config) in 4.x
{ "ts-node": { "files": true, "esm": true, "experimentalSpecifierResolution": "node" }, "compilerOptions": { "target": "es2022", "lib": ["es2022", "DOM"], "esModuleInterop": true, "module": "esnext", "moduleResolution": "node", "strictNullChecks": false, "types": ["codeceptjs", "node"], "declaration": true, "skipLibCheck": true, }, "exclude": ["node_modules"], }PO
pages/Login.ts:test
My_test.tsTest fails ❌
If you use the default option
"module": "commonjs", it works well ✔️So a question is: How to setup PO for the suggested ESM module setting?
Used SW:
<agent_instructions>- investigate and fix issue
Comments on the Issue (you are @copilot in this section)
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.