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

Importing @streamparser/json results in error when using tsc or jest relying on tsc #516

Closed
tegefaulkes opened this issue Mar 21, 2023 · 8 comments · Fixed by #513
Closed
Assignees
Labels
development Standard development r&d:polykey:core activity 1 Secret Vault Sharing and Secret History Management

Comments

@tegefaulkes
Copy link
Contributor

Specification

As part of #249 we're using a JSON stream parser to parse the JSONRPC messages. There seems to be a problem with this library specifically where we can't import it with the import keyword. So far a work around has been to import it with const jsonStreamParsers = require('@streamparser/json');.

We need to import it with import { JSONParser } from '@streamparser/json';. but currently doing so results in a TS2307: Cannot find module '@streamparser/json' or its corresponding type declarations. error.

So far I haven't been able to determine why the usual import isn't working. From what I can tell it's using conditional exports within it's package.json file for specifying the exports. This may be related?

Additional context

Tasks

  1. determine the cause of the import error.
  2. find a fix to import the stream parser using the import keyword.
@tegefaulkes tegefaulkes added the development Standard development label Mar 21, 2023
@tegefaulkes tegefaulkes self-assigned this Mar 21, 2023
@tegefaulkes
Copy link
Contributor Author

Created an upstream issue at juanjoDiaz/streamparser-json#25.

@CMCDragonkai
Copy link
Member

CMCDragonkai commented Mar 21, 2023

This works fine in a prototyping script:

import { JSONParser } from '@streamparser/json';

async function main() {
  console.log(JSONParser);
}

main();

It's only the IDE that complains. Running npm run ts-node -- ./test.ts works.

> [email protected] ts-node
> ts-node "./test.ts"

[class JSONParser]

@CMCDragonkai
Copy link
Member

Are you getting that error when running JEST tests? If not, then ignore the IDE, and just proceed. It's just an IDE configuration issue.

@CMCDragonkai
Copy link
Member

I see... it fails in jest, but works in ts-node.

@CMCDragonkai
Copy link
Member

Note that our ts-node is in fact using swc, whereas jest is not currently using swc.

@CMCDragonkai
Copy link
Member

I think this is related to: MatrixAI/TypeScript-Demo-Lib#32. The package appears to be module type. But it must be breaking on resolution somehow.

@CMCDragonkai
Copy link
Member

Here you can see the issue:

tsc ./test.ts
test.ts:1:28 - error TS2307: Cannot find module '@streamparser/json' or its corresponding type declarations.

But if I use swc it ends up keeping it as regular imports.

I think this is because our tsconfig.json specifies CommonJS modules. Perhaps upstream package isn't well tested with commonjs tsconfigs.

@CMCDragonkai CMCDragonkai changed the title streamParser import error Importing @streamparser/json results in error when using tsc or jest relying on tsc Mar 21, 2023
@CMCDragonkai
Copy link
Member

This should be done with the merge of #513.

@CMCDragonkai CMCDragonkai added the r&d:polykey:core activity 1 Secret Vault Sharing and Secret History Management label Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Standard development r&d:polykey:core activity 1 Secret Vault Sharing and Secret History Management
Development

Successfully merging a pull request may close this issue.

2 participants