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

fix(store,world): fix tsc errors in projects depending on @latticexyz/store-sync #1974

Merged
merged 2 commits into from
Nov 30, 2023

Conversation

tash-2s
Copy link
Contributor

@tash-2s tash-2s commented Nov 29, 2023

Projects created by create-mud are currently failing their pnpm test scripts due to TypeScript type checking errors. This pull request addresses this issue and also resolves #1958.

Steps to Reproduce

# Create a new project
$ pnpm create [email protected] my-project --template vanilla
$ cd my-project

# Add missing dependencies to prevent other tsc errors
# I can address this issue in a separate PR
$ pnpm --filter contracts add --save-dev @types/[email protected] @types/[email protected]
$ pnpm --filter client add --save-dev @types/[email protected] @types/[email protected] @types/[email protected] @types/[email protected]

# Test and see the errors
$ pnpm test # runs `pnpm -r run test` and fails, showing the log below
$ pnpm --filter client test
> [email protected] test /Users/t/bench/my-project/packages/client
> tsc --noEmit

../../node_modules/.pnpm/@[email protected]_@[email protected][email protected]_typescript
@5.1.6/node_modules/@latticexyz/store-sync/src/common.ts:6:25 - error TS2307: Cannot find module '@lattice
xyz/store/mud.config' or its corresponding type declarations.

6 import storeConfig from "@latticexyz/store/mud.config";
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../../node_modules/.pnpm/@[email protected]_@[email protected][email protected]_typescript
@5.1.6/node_modules/@latticexyz/store-sync/src/common.ts:7:25 - error TS2307: Cannot find module '@lattice
xyz/world/mud.config' or its corresponding type declarations.

7 import worldConfig from "@latticexyz/world/mud.config";
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../../node_modules/.pnpm/@[email protected]_@[email protected][email protected]_typescript
@5.1.6/node_modules/@latticexyz/store-sync/src/internalTableIds.ts:2:25 - error TS2307: Cannot find module
 '@latticexyz/store/mud.config' or its corresponding type declarations.

2 import storeConfig from "@latticexyz/store/mud.config";
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../../node_modules/.pnpm/@[email protected]_@[email protected][email protected]_typescript
@5.1.6/node_modules/@latticexyz/store-sync/src/internalTableIds.ts:3:25 - error TS2307: Cannot find module
 '@latticexyz/world/mud.config' or its corresponding type declarations.

3 import worldConfig from "@latticexyz/world/mud.config";
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../../node_modules/.pnpm/@[email protected]_@[email protected][email protected]_typescript
@5.1.6/node_modules/@latticexyz/store-sync/src/recs/recsStorage.ts:14:25 - error TS2307: Cannot find modul
e '@latticexyz/store/mud.config' or its corresponding type declarations.

14 import storeConfig from "@latticexyz/store/mud.config";
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../../node_modules/.pnpm/@[email protected]_@[email protected][email protected]_typescript
@5.1.6/node_modules/@latticexyz/store-sync/src/recs/recsStorage.ts:15:25 - error TS2307: Cannot find modul
e '@latticexyz/world/mud.config' or its corresponding type declarations.

15 import worldConfig from "@latticexyz/world/mud.config";
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 6 errors in 3 files.

Errors  Files
     2  ../../node_modules/.pnpm/@[email protected]_@[email protected][email protected]_ty
[email protected]/node_modules/@latticexyz/store-sync/src/common.ts:6
     2  ../../node_modules/.pnpm/@[email protected]_@[email protected][email protected]_ty
[email protected]/node_modules/@latticexyz/store-sync/src/internalTableIds.ts:2
     2  ../../node_modules/.pnpm/@[email protected]_@[email protected][email protected]_ty
[email protected]/node_modules/@latticexyz/store-sync/src/recs/recsStorage.ts:14
/Users/t/bench/my-project/packages/client:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  [email protected] test: `tsc --noEmit`
Exit status 2

Cause

These errors occur because the published store and world packages don't contain the /mud.config.ts files. In the MUD repository's /templates/vanilla/, these errors don't occur, as it uses locally linked dependencies (like "@latticexyz/store-sync": "link:../../../../packages/store-sync").

In the package.json files of both store and world, the typesVersions fields for TypeScript don't include /mud.config, so the @latticexyz/<name>/mud.config imports are resolved by their file paths.

Fix

To resolve this, I've added !mud.config.ts to the .npmignore files of both store and world to include these files in the published packages.

To verify the fix of these errors, you can follow these steps after checking out this branch:

# Package
$ cd packages/store
$ pnpm pack
$ cd ../world
$ pnpm pack

# Go to the project where the error was reproduced
$ cd /path/to/my-project

# Replace the packages
$ pnpm --filter client add /path/to/mud/packages/store/latticexyz-store-2.0.0-next.14.tgz /path/to/mud/packages/world/latticexyz-world-2.0.0-next.14.tgz

# Re-run the tests that previously failed
$ pnpm --filter client test # passes without any errors

Note

While this fix addresses the immediate issue for projects with store-sync dependencies, I'm considering whether the current packaging approach of using typesVersions is optimal. Currently, users are required to have moduleResolution: node10 in their tsconfig.json, but I prefer using node16 or bundler for my project. I believe this topic has already been discussed within the team. If there are any established ideas or directions regarding this issue, I'd be eager to learn and contribute.

@tash-2s tash-2s requested review from alvrs and holic as code owners November 29, 2023 22:26
Copy link

changeset-bot bot commented Nov 29, 2023

🦋 Changeset detected

Latest commit: 56fcff9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@latticexyz/store Patch
@latticexyz/world Patch
@latticexyz/cli Patch
@latticexyz/dev-tools Patch
@latticexyz/react Patch
@latticexyz/store-indexer Patch
@latticexyz/store-sync Patch
@latticexyz/world-modules Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/common Patch
@latticexyz/config Patch
create-mud Patch
@latticexyz/ecs-browser Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/network Patch
@latticexyz/noise Patch
@latticexyz/phaserx Patch
@latticexyz/protocol-parser Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
@latticexyz/services Patch
@latticexyz/solecs Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/std-client Patch
@latticexyz/std-contracts Patch
@latticexyz/store-cache Patch
@latticexyz/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@holic holic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much!

@holic holic merged commit 1077c7f into latticexyz:main Nov 30, 2023
10 checks passed
@tash-2s tash-2s deleted the fix-tsc-error branch November 30, 2023 19:11
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 this pull request may close these issues.

Calling encodeEntity in vitetest causes import error from @latticexyz/store-sync
2 participants