Skip to content

ts will try to compile import files from a folder without reference or include #61440

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

Closed
HolgerJeromin opened this issue Mar 17, 2025 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@HolgerJeromin
Copy link
Contributor

HolgerJeromin commented Mar 17, 2025

πŸ”Ž Search Terms

module import declaration

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried 3.3 and 5.9-nightly

⏯ Playground Link

https://github.com/HolgerJeromin/ts-issues/tree/ts-61440

πŸ’» Code

Folder jsModule with tsconfig and one module file:

file jsModule/jsModule.ts

export class TreeView {
  constructor() {
    Promise.allSettled([]);
  }
}

jsModule/tsconfig.json

{
  "compilerOptions": {
    "composite": true,
    "module": "ES2020",
    "target": "ES2015",
    "lib": ["DOM", "ES2015", "ES2020"],
    "strict": true
  },
  "files": ["jsModule.ts"]
}

And a folder src:

file src/main.ts

import { TreeView } from "../jsModule/jsModule.js";
const _TreeView = new TreeView();

src/tsconfig.json

{
  "$schema": "http://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "module": "ES2022",
    "target": "ES2022",
    "lib": ["ES2015", "DOM"],
    "types": [],

    "strict": true
  },
  "files": ["main.ts"]
}

Note: No ES2020 lib.

πŸ™ Actual behavior

Build jsModule folder:

.\node_modules\.bin\tsc.cmd --build  .\jsModule\ --verbose

Results in emit of correct jsModule/jsModule.js and .d.ts file.
Build src folder:

.\node_modules\.bin\tsc.cmd --build  .\src\ --verbose

fails to compile because it uses not the correct tsconfig:

.\node_modules\.bin\tsc.cmd --build  .\src\ --verbose  --explainFiles
[16:15:17] Projects in this build: 
    * src/tsconfig.json

[16:15:17] Project 'src/tsconfig.json' is out of date because buildinfo file 'src/tsconfig.tsbuildinfo' indicates that program needs to report errors.

[16:15:17] Building project '/ts-issues/src/tsconfig.json'...

jsModule/jsModule.ts:3:13 - error TS2550: Property 'allSettled' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.

3     Promise.allSettled([])
              ~~~~~~~~~~

node_modules/typescript/lib/lib.es5.d.ts
  Library referenced via 'es5' from file 'node_modules/typescript/lib/lib.es2015.d.ts'
node_modules/typescript/lib/lib.es2015.d.ts
  [...]
node_modules/typescript/lib/lib.decorators.d.ts
  Library referenced via 'decorators' from file 'node_modules/typescript/lib/lib.es5.d.ts'
node_modules/typescript/lib/lib.decorators.legacy.d.ts
  Library referenced via 'decorators.legacy' from file 'node_modules/typescript/lib/lib.es5.d.ts'
jsModule/jsModule.ts
  Imported via "../jsModule/jsModule.js" from file 'src/main.ts'
src/main.ts
  Part of 'files' list in tsconfig.json

Found 1 error.

πŸ™‚ Expected behavior

The build failure is surprising.
Expected would be one of

  • The files are not included (or referenced) in src/tsconfig.json so they should not be rebuild (but only .d.ts files consumed) or
  • if this needs to be rebuild it should be correctly based on its tsconfig.json

Additional information about the issue

With my real code these folders are different VS 2022 projects and therefore have no references.
Instead I have many different tsconfig.json files for the esm files. So wildly importing some ts files into the compile will never get a reasonable output. (but break the output js files in imported folder).

Found #15272 but we had no references back in 2017.
Perhaps is this a simplified version of #58353

@MartinJohns
Copy link
Contributor

  • The files are not included (or referenced) in src/tsconfig.json so they should not be rebuild (but only .d.ts files consumed) or

This is working as intended. The included files are the starting point of the compilation, but whatever local files you import become part of the compilation.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Mar 17, 2025
@RyanCavanaugh
Copy link
Member

The files are not included (or referenced) in src/tsconfig.json so they should not be rebuild (but only .d.ts files consumed)

You need to use project references if you want this to happen

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2025
@HolgerJeromin
Copy link
Contributor Author

HolgerJeromin commented Mar 20, 2025

I had compile problems when using project references in my very complex monorepo.

So I moved my .ts files out of the way by using outDir so the consumer is not able to find source files to compile...

Thanks for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants