Skip to content

TypeError: state.conditions.includes is not a function in recent TS versions when running with ts-node #56508

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
vladfrangu opened this issue Nov 22, 2023 · 4 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@vladfrangu
Copy link

vladfrangu commented Nov 22, 2023

🔎 Search Terms

ts-node, tsnode, state.conditions.includes, typeerror

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions 5.2.2 and 5.3.2
  • This changed in commit or PR 1b70ac3 (at least I think so, bisecting with every-ts had me fluctuating with this unrelated error:
/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:6595
    return path.length > extension.length && endsWith(path, extension);
                ^
TypeError: Cannot read properties of undefined (reading 'length')
    at fileExtensionIs (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:6595:17)
    at shouldEmitSourceMaps (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:112383:124)
    at printSourceFileOrBundle (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:112324:11)
    at emitJsFileOrBundle (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:112219:7)
    at emitSourceFileOrBundle (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:112122:7)
    at forEachEmittedFile (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:111876:26)
    at emitFiles (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:112096:5)
    at emitWorker (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:119594:26)
    at /Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:119579:53
    at runWithCancellationToken (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:119668:16)

⏯ Playground Link

https://github.com/vladfrangu/ts5.3-ts-node-issue

💻 Code

N/A, seems to be related to either a change in TS or an edge case when running it through ts-node

🙁 Actual behavior

TS fails to run when invoked via ts-node

🙂 Expected behavior

TS works fine when invoked via ts-node

Additional information about the issue

Adding a console.log({ condition, state }) above the line that throws yields

{
  condition: 'import',
  state: {
    compilerOptions: { moduleResolution: 2 },
    host: {
      fileExists: [Function: fileExists],
      readDirectory: [Function: readDirectory],
      readFile: [Function: readFile],
      useCaseSensitiveFileNames: false,
      trace: [Function: bound log]
    },
    traceEnabled: false,
    failedLookupLocations: [],
    affectingLocations: [
      '/Users/vlad/Development/Apify/__tests__/tsctsnodeerror/package.json',
      '/Users/vlad/Development/Apify/__tests__/tsctsnodeerror/node_modules/@apify/tsconfig/package.json'
    ],
    packageJsonInfoCache: undefined,
    features: 30,
    conditions: true,
    requestContainingDirectory: '/Users/vlad/Development/Apify/__tests__/tsctsnodeerror',
    reportDiagnostic: [Function: reportDiagnostic],
    isConfigLookup: false,
    candidateIsFromPackageJsonField: false
  }
}

Stacktrace

/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:41230
            if (condition === "default" || state.conditions.includes(condition) || isApplicableVersionedTypesKey(state.conditions, condition)) {
                                                            ^

TypeError: state.conditions.includes is not a function
    at loadModuleFromTargetImportOrExport (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:41230:61)
    at loadModuleFromExports (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:40970:16)
    at loadModuleFromSpecificNodeModulesDirectory (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:41490:20)
    at loadModuleFromImmediateNodeModulesDirectory (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:41433:29)
    at /Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:41421:33
    at forEachAncestorDirectory (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:6963:22)
    at lookup (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:41415:14)
    at loadModuleFromNearestNodeModulesDirectoryWorker (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:41406:22)
    at loadModuleFromNearestNodeModulesDirectory (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:41375:12)
    at tryResolve (/Users/vlad/.volta/tools/image/packages/every-ts/lib/node_modules/every-ts/.data/TypeScript/lib/typescript.js:40424:23)

Node.js v20.9.0

It seems like somehow state.conditions is a boolean instead of an array. I am not sure if this is something ts-node is doing or some very specific edge case in tsc, so I apologize in advance if this is the wrong repo.

To test this with every-ts, I had to manually point typescript to the path of the module, as the suggested npm link $(every-ts dir) command did not work.

@andrewbranch
Copy link
Member

If you’re not able to repro this with tsc, I think it’s safe to say this is ts-node 🤔

@andrewbranch andrewbranch added the External Relates to another program, environment, or user action which we cannot control. label Nov 22, 2023
@andrewbranch
Copy link
Member

Same root cause as #56492

@vladfrangu
Copy link
Author

vladfrangu commented Nov 22, 2023

I'll open an issue on their repository pointing to this and #56492 then, thanks!

Sneak edit: seems like it's been reported already, so time to patiently wait

@typescript-bot
Copy link
Collaborator

This issue has been marked as "External" 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 Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

3 participants