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

tsconfck module cannot be found #907

Closed
Amndeep7 opened this issue Dec 22, 2023 · 2 comments · Fixed by #892
Closed

tsconfck module cannot be found #907

Amndeep7 opened this issue Dec 22, 2023 · 2 comments · Fixed by #892

Comments

@Amndeep7
Copy link

Describe the bug
tsconfck as a module cannot be found for some reason.

Originally discovered when this workflow started failing in one of our repos: https://github.com/mitre/saf_action/actions/runs/7285825454/job/19853410684. The specific issue there was that jest started segfaulting. Tracing the code showed that the crash occurred when trying to dynamically import tsconfck here.

I originally thought that the issue might have had something to do with using dynamic imports, so I tried to statically import the library using the following patch:

patch to src/util/fs.ts
diff --git a/src/util/fs.ts b/src/util/fs.ts
index 0e09e7c..3b5022f 100644
--- a/src/util/fs.ts
+++ b/src/util/fs.ts
@@ -1,6 +1,7 @@
 import {Stats, existsSync as fsExistsSync, readFileSync} from 'node:fs'
 import {readFile, stat} from 'node:fs/promises'
 import {join} from 'node:path'
+import {parse as tsparse} from 'tsconfck'

 import {mergeNestedObjects} from './util'

@@ -73,8 +74,7 @@ export function existsSync(path: string): boolean {
 }

 export async function readTSConfig(path: string) {
-  const {parse} = await import('tsconfck')
-  const result = await parse(path)
+  const result = await tsparse(path)
   const tsNodeOpts = mergeNestedObjects(result.extended ?? [result], 'tsconfig.ts-node')
   return {...result.tsconfig, 'ts-node': tsNodeOpts}
 }

When trying to build the project, it gave the following error: Cannot find module 'tsconfck' or its corresponding type declarations..

Full `yarn pack` output
$ yarn pack
yarn pack v1.22.21
$ yarn run build
yarn run v1.22.21
$ shx rm -rf lib && tsc
src/util/fs.ts:4:32 - error TS2307: Cannot find module 'tsconfck' or its corresponding type declarations.

4 import {parse as tsparse} from 'tsconfck'
                                 ~~~~~~~~~~


Found 1 error in src/util/fs.ts:4

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/pack for documentation about this command.

Presumably this inability to resolve the module is also occurring when we try to do the dynamic import in the original code.

To Reproduce
Steps to reproduce the behavior:
Variant 1:

  1. Apply the patch provided above to the repo.
  2. Run yarn pack

Variant 2:

  1. Run npx ts-node in a clone of oclif/core after having run yarn install --frozen-lockfile.
  2. Sanity test by running import {basename, dirname, join} from 'node:path' to see that you can import modules.
  3. Run import {parse} from 'tsconfck' and see it error out.
ts-node output
$ npx ts-node
> import {basename, dirname, join} from 'node:path'
undefined
> import {parse} from 'tsconfck'
<repl>.ts:5:21 - error TS2307: Cannot find module 'tsconfck' or its corresponding type declarations.

5 import {parse} from 'tsconfck'

Expected behavior
The library should be able to be found.

Environment (please complete the following information):

  • OS & version: MacOS Venture 13.6.3
  • Shell/terminal & version: bash-5.2.21
  • Node version: 18.18.2
  • Yarn version: 1.22.21

Additional context
Looks like folks are having other problems with tsconfck as well: #878.

Looks like tsconfck removed support for cjs exports: https://github.com/dominikg/tsconfck/releases/tag/tsconfck%403.0.0

@mdonnalley
Copy link
Contributor

@Amndeep7 Do you have any logs or stack traces that the indicate the dynamic import of tsconfck is the issue? I'm leaning towards this being specific to jest and/or your testing setup

Regardless, we're working on removing the tsconfck dependency so this may not be an issue for you anymore in a couple of weeks

@Amndeep7
Copy link
Author

Amndeep7 commented Jan 2, 2024

@mdonnalley I believe the issue is with trying to import tsconfck at all. It fails during both static and dynamic imports as detailed above. In any case, it being removed as a dependency should ideally resolve the issue.

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

Successfully merging a pull request may close this issue.

2 participants