Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript 5.7 breaks "module"="NodeNext" #60571

Open
FranzZemen opened this issue Nov 23, 2024 · 0 comments
Open

Typescript 5.7 breaks "module"="NodeNext" #60571

FranzZemen opened this issue Nov 23, 2024 · 0 comments

Comments

@FranzZemen
Copy link

🔎 Search Terms

Typescript 5.7 breaks features provided by "module"="NodeNext", specfically the ability to import via either the package name or through an package.json imports definition.

With 5.7.* when using the package name by way of an package.json exports or a project name by way of the package.json imports feature, we get errors like:

File '/home/franzzemen/dev/typescript5.7.2-defect/src/project/dummy/dummy.ts' is not under 'rootDir' '/home/franzzemen/dev/typescript5.7.2-defect/src/test'. 'rootDir' is expected to contain all source files.
  File is ECMAScript module because '/home/franzzemen/dev/typescript5.7.2-defect/package.json' has field "type" with value "module"

These errors are not observed in prior versions.

A sample repository to repeat this issue is provided in https://github.com/FranzZemen/typescript5.7.2-defect

It currently builds using: "typescript": "^5.6.3". The build fails when upgrading typescript.

The project contains a dummy.ts source file in a project folder, and a dummy.test.ts which refers to the dummy.ts via an import from the #project symbol defined in the package.json.

🕗 Version & Regression Information

  • This changed between versions 5.6.3 and 5.7.2

⏯ Playground Link

No response

💻 Code

A sample repository to repeat this issue is provided in https://Github.com/FranzZemen/typescript5.7.2-defect

It currently builds using: "typescript": "^5.6.3". The build fails when upgrading typescript.

Files:

tsconfig.json

'''json
{
"files": [],
"include": [],
"references": [
{
"path": "./src/project/tsconfig.json"
},
{
"path": "./src/test/tsconfig.json"
}
]
}
'''

tsconfig.base.json

'''json
{
"compilerOptions": {
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"alwaysStrict": false,
"exactOptionalPropertyTypes": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedParameters": false,
"strict": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"useUnknownInCatchVariables": true,
"allowJs": true,
"checkJs": true,
"maxNodeModuleJsDepth": 0,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": false,
"preserveSymlinks": true,
"emitDeclarationOnly": false,
"downlevelIteration": true,
"emitBOM": false,
"importHelpers": true,
"importsNotUsedAsValues": "remove",
"noEmit": false,
"noEmitHelpers": false,
"noEmitOnError": false,
"preserveConstEnums": false,
"preserveValueImports": false,
"newLine": "crlf",
"composite": true,
"incremental": true,
"declaration": true,
"sourceMap": true,
"noErrorTruncation": true,
"pretty": true
}
}
'''

package.json

'''json
{
"name": "typescript5.7.2-defect",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/chai": "^5.0.1",
"@types/mocha": "^10.0.10",
"chai": "^5.1.2",
"mocha": "^10.8.2"
},
"type": "module",
"exports": {
".": {
"import": "./src/project/index.ts"
}
},
"imports": {
"#project": "./src/project/project-index.ts"
},
"dependencies": {
"typescript": "^5.6.3"
}
}

'''

/test/dummy.test.ts

'''ts
/*
Created by Franz Zemen 11/23/2024
License Type:
*/

import 'mocha';
import {expect} from 'chai';
import {helloWorld} from '#project';

describe('dummy test', () => {
it('should pass', () => {
expect(helloWorld()).to.equal(' World!');
});
});
'''

/test/tsconfig.json

'''json
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "NodeNext",
"tsBuildInfoFile": "../../out/buildInfo/testTsInfo",
"declarationDir": "../../out/test/types",
"outDir": "../../out/test"
},
"include": [
"**/*"
]
}
'''

/project/index.ts

'''ts
/*
Created by Franz Zemen 11/23/2024
License Type:
*/

export * from './dummy/dummy.js';
'''

/project/project-index.ts

'''ts
/*
Created by Franz Zemen 11/23/2024
License Type:
*/

export * from './dummy/dummy.js';
'''
/project/tsconfig.json

'''json
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "NodeNext",
"tsBuildInfoFile": "../../out/buildInfo/projectTsInfo",
"declarationDir": "../../out/project/types",
"outDir": "../../out/project"
},
"include": [
"**/*"
]
}
'''

/project/dummy/dummy.ts

'''ts
/*
Created by Franz Zemen 11/23/2024
License Type:
*/

export function helloWorld() {
return 'Hello World!';
}
'''

🙁 Actual behavior

Transpile error, wrong because all settings for NodeNext are properly set and works with prior versions of typescript

🙂 Expected behavior

Transpilation without errors

Additional information about the issue

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant