Vexilla / vexilla

Other
29 stars 9 forks source link

Compilation Failure: TypeScript Unable to Compile Due to Missing @types/Vexilla Definitions #33

Open ChristopherHarwell opened 8 months ago

ChristopherHarwell commented 8 months ago

Prerequisites

Description

When attempting to compile the TypeScript project using the pnpm compile command within our Vexilla client setup, we encounter several compilation errors that seem to stem from missing module declarations and incorrect module exports. Below are the details of the errors received during compilation:

When running the pnpm test and pnpm test:scheduling commands in the context of our Vexilla JavaScript client setup, we encounter a situation mirroring the issues faced during the pnpm compile process, but with additional implications for our testing workflow. These commands are designed to execute unit tests to verify the integrity and functionality of our codebase, but the presence of compilation errors obstructs this essential verification process.

The errors encountered are twofold and closely resemble those observed during compilation:

  1. Missing Type Declarations for @vexilla/types: Similar to the compilation phase, when attempting to run tests, TypeScript reports an inability to locate the module @vexilla/types or its corresponding type declarations across multiple files. This issue is prevalent in files such as client.ts, scheduling.ts, test_client.ts, test_distribution.ts, test_scheduling.ts, and utils/lookup_tables.ts. The repeated occurrence of this error in the testing phase underscores a possible systemic issue with how the @vexilla/types package is integrated or referenced within the project, suggesting a critical need for revisiting the package installation or TypeScript's configuration setup to ensure proper recognition of type declarations.

  2. Incorrect Module Exports from /src/hasher: The tests also fail due to errors concerning module imports, particularly pointing out that the src/hasher module does not have a default export. This problem is highlighted in files like generate_gradual_uuid.ts, generate_seed_for_uuid.ts, and test_distribution.ts. This indicates a discrepancy between the expectation of default exports within the consuming files and the actual export structure of the src/hasher module, hinting at a misalignment in the export/import statements that needs to be corrected for successful test execution.

The culmination of these errors during the test execution phase (pnpm test and pnpm test:scheduling) not only halts the testing process but also raises concerns about the project's current state of modularity and type-safety. It highlights a critical barrier to maintaining code quality and reliability, as the inability to run tests due to compilation errors prevents validation of code changes and the assurance of functionality through automated testing. Addressing these issues is paramount to resuming a productive development and testing cycle, ensuring that the Vexilla JavaScript client adheres to expected standards of quality and robustness.

The exact error message for pnpm compile are as follows:

> @vexilla/client@1.0.0 compile /Users/guest1/Documents/1_Projects/vexilla/clients/js
> tsc

src/client.ts(13,8): error TS2307: Cannot find module '@vexilla/types' or its corresponding type declarations.
src/generate_gradual_uuid.ts(2,8): error TS1192: Module '"/Users/guest1/Documents/1_Projects/vexilla/clients/js/src/hasher"' has no default export.
src/generate_seed_for_uuid.ts(2,8): error TS1192: Module '"/Users/guest1/Documents/1_Projects/vexilla/clients/js/src/hasher"' has no default export.
src/scheduling.ts(9,8): error TS2307: Cannot find module '@vexilla/types' or its corresponding type declarations.
src/test_client.ts(1,33): error TS2307: Cannot find module '@vexilla/types' or its corresponding type declarations.
src/test_distribution.ts(3,8): error TS1192: Module '"/Users/guest1/Documents/1_Projects/vexilla/clients/js/src/hasher"' has no default export.
src/test_scheduling.ts(1,33): error TS2307: Cannot find module '@vexilla/types' or its corresponding type declarations.
src/utils/lookup_tables.ts(5,8): error TS2307: Cannot find module '@vexilla/types' or its corresponding type declarations.
 ELIFECYCLE  Command failed with exit code 2.

The exact error message for pnpm test are as follows:

> @vexilla/client@1.0.0 test /Users/guest1/Documents/1_Projects/vexilla/clients/js
> pnpm run "/^test:.*/"

> @vexilla/client@1.0.0 test:gradual /Users/guest1/Documents/1_Projects/vexilla/clients/js
> ts-node src/test_gradual.ts

> @vexilla/client@1.0.0 test:scheduling /Users/guest1/Documents/1_Projects/vexilla/clients/js
> ts-node src/test_scheduling.ts

> @vexilla/client@1.0.0 test:client /Users/guest1/Documents/1_Projects/vexilla/clients/js
> ts-node src/test_client.ts

WORKING SEED 0.28
NON WORKING SEED 0.56
/Users/guest1/Documents/1_Projects/vexilla/clients/js/src/test_gradual.ts:13
assert.ok(hashString(uuid, workingSeed) > 0.4);
       ^
AssertionError [ERR_ASSERTION]: false == true
    at Object.<anonymous> (/Users/guest1/Documents/1_Projects/vexilla/clients/js/src/test_gradual.ts:13:8)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module.m._compile (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at phase4 (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/bin.ts:649:14)
    at bootstrap (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/bin.ts:95:10) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}
 ELIFECYCLE  Command failed with exit code 1.
/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/test_scheduling.ts:1:33 - error TS2307: Cannot find module '@vexilla/types' or its corresponding type declarations.

1 import { VexillaSchedule } from "@vexilla/types";
                                  ~~~~~~~~~~~~~~~~

    at createTSError (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) {
  diagnosticCodes: [ 2307 ]
}
/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/test_client.ts:1:33 - error TS2307: Cannot find module '@vexilla/types' or its corresponding type declarations.

1 import { VexillaManifest } from "@vexilla/types";
                                  ~~~~~~~~~~~~~~~~

    at createTSError (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) {
  diagnosticCodes: [ 2307 ]
}
 ELIFECYCLE  Test failed. See above for more details.

The exact error message for pnpm test:scheduling are as follows:

> @vexilla/client@1.0.0 test:scheduling /Users/guest1/Documents/1_Projects/vexilla/clients/js
> ts-node src/test_scheduling.ts

/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/test_scheduling.ts:1:33 - error TS2307: Cannot find module '@vexilla/types' or its corresponding type declarations.

1 import { VexillaSchedule } from "@vexilla/types";
                                  ~~~~~~~~~~~~~~~~

    at createTSError (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/guest1/Documents/1_Projects/vexilla/node_modules/.pnpm/ts-node@10.9.1_@types+node@14.18.46_typescript@5.2.2/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) {
  diagnosticCodes: [ 2307 ]
}
 ELIFECYCLE  Command failed with exit code 1.

This issue has halted our development process as we cannot proceed without resolving these compilation errors. It seems that there might be a need for clearer documentation on the setup or perhaps an update to ensure that the necessary type declarations and module exports are correctly defined and available. Any assistance or guidance on resolving these errors would be greatly appreciated.

Steps to Reproduce

To reproduce the TypeScript compilation issue encountered with the Vexilla client, follow these detailed steps:

  1. Start the Test Server:

    • Open a terminal window.
    • Navigate to the test server directory within the Vexilla project structure by running:
      cd /path/to/vexilla/packages/test

      Replace /path/to/vexilla with the actual path to your Vexilla project.

    • Start the test server by executing:
      pnpm start
    • Ensure the test server is running without any errors.
  2. Run the JS Client Tests:

    • Open a new terminal window (leaving the test server running in the original terminal).
    • Navigate to the JavaScript client directory within the Vexilla project by running:
      cd /path/to/vexilla/clients/js

      Again, replace /path/to/vexilla with the actual path to your Vexilla project.

    • Execute the test command:
      pnpm test
    1. Run the JS Client Tests for scheduling:

      • Open a new terminal window (leaving the test server running in the original terminal).
      • Navigate to the JavaScript client directory within the Vexilla project by running:
        cd /path/to/vexilla/clients/js

        Again, replace /path/to/vexilla with the actual path to your Vexilla project.

      • Execute the test command:
        pnpm test:scheduling
    2. Run the TypeScript Compilation script for the JS Client:

      • Open a new terminal window (leaving the test server running in the original terminal).
      • Navigate to the JavaScript client directory within the Vexilla project by running:
        cd /path/to/vexilla/clients/js

        Again, replace /path/to/vexilla with the actual path to your Vexilla project.

      • Execute the test command:
        pnpm compile
    • Observe the output in the terminal, which should display the compilation errors related to missing module declarations for @vexilla/types.

By following these steps, you should encounter the specific TypeScript compilation errors previously mentioned, indicating issues with missing type declarations and incorrect module export/import usage within the Vexilla JavaScript client project.


Expected behavior: Upon navigating to the appropriate directory and starting the test server located at vexilla/packages/test with the pnpm start command, followed by running pnpm test from another terminal in the JavaScript client directory at vexilla/clients/js, the expected behavior is that all tests should execute successfully without any compilation errors.

Actual behavior: The actual behavior observed when attempting to run tests for the Vexilla JavaScript client is a series of compilation errors that prevent the execution of the tests. Upon navigating to the Vexilla JS client directory and executing pnpm test, TypeScript compilation fails with multiple errors. These errors primarily concern missing module declarations for @vexilla/types across various files and issues with module imports, notably from the src/hasher module, which is reported to lack a default export. This results in the test command exiting with an error code (ELIFECYCLE Command failed with exit code 2), indicating that the tests cannot be run as expected due to these compilation issues.


Environment

Additional Context

Output of running pnpm test:

Screenshot 2024-02-25 at 08 53 19

Output of running pnpm test:scheduling:

Screenshot 2024-02-25 at 08 54 08

Output of running pnpm compile:

Screenshot 2024-02-25 at 09 11 16

node, pnpm, and npm versions:

Screenshot 2024-02-25 at 08 57 52
cmgriffing commented 8 months ago

Awesome Issue. Very thorough. Thanks!

After our discussion, I believe you needed to run pnpm install from the project root rather than the js client folder. This is because pnpm needs to link dependencies within the workspace.

The Hasher bug, was definitely just a bug from a previous refactor that we missed. It should be updated and fixed once I merge my start-end-fix branch.

Let me know if you get it working with the top level install. If not, happy to troubleshoot it more.

ChristopherHarwell commented 8 months ago

So after running pnpm install from the top level, it seems I am still running into the @Vexilla/types missing compilation error in the JS SDK.

I can provide more info tomorrow once I have some more time to look into why that might be happening. Haven't worked on trying to fix it in a few days. But plan on trying to get this working this weekend.

cmgriffing commented 6 months ago

I think this was related to the missing .env file. Could you try removing the whole thing, recloning, and then reinstalling before a recompile?

cmgriffing commented 6 months ago

I also just pushed up some changes that fix the Hasher problems:

Additionally, there are errors related to module imports from /src/hasher, specifically stating that the module has no default export (generate_gradual_uuid.ts, generate_seed_for_uuid.ts, test_distribution.ts). This implies a potential mismatch between the exported and imported entities in these modules.