ts-node
ts-node copied to clipboard
`preferTsExts` incorrectly imports `.js` instead of `.ts` when importing an inferred `index` file
Search Terms
"preferTsExts", "coverage", "index"
Expected Behavior
Following the below steps should result in 100% code coverage at all times
Actual Behavior
Coverage is not 100%
Steps to reproduce the problem
- Clone this repo
-
npm i -
npm test - Note 100% coverage, including
packages/object-id/index.ts -
npm run build -
npm test - Now note less coverage:
packages/object-id/index.tsis uncovered, becausepackages/object-id/index.jsis being used instead - Reset using
npm run build:clean, and coverage returns to 100%
Minimal reproduction
https://github.com/alecgibson/ts-node-prefer-ts-exts-bug
Specifications
- ts-node version: 10.9.1
- node version: v18.10.0
- TypeScript version: ^4.9.5
- tsconfig.json, if you're using one:
{
"compilerOptions": {},
"include": [
"lib/",
"packages/",
],
"ts-node": {
"preferTsExts": true,
},
}
- package.json:
{
"name": "ts-node-prefer-ts-exts-bug",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"build:clean": "tsc --build --clean",
"test": "nyc mocha -r ts-node/register 'lib/**/*.spec.ts' 'packages/**/*.spec.ts'"
},
"repository": {
"type": "git",
"url": "git+https://github.com/alecgibson/ts-node-prefer-ts-exts-bug.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/alecgibson/ts-node-prefer-ts-exts-bug/issues"
},
"homepage": "https://github.com/alecgibson/ts-node-prefer-ts-exts-bug#readme",
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"dependencies": {
}
}
- Operating system and version: macOS 13.2.1 (22D68)
Notes
Here are some things I've noted trying to put together the MWE:
- Changing this line fixes the issue:
- import {isObjectId} from '.';
+ import {isObjectId} from './index';
- The same thing is true of this line:
- import {isObjectId} from '../packages/object-id';
+ import {isObjectId} from '../packages/object-id/index';