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

Error importing JSONParser #25

Closed
tegefaulkes opened this issue Mar 21, 2023 · 10 comments
Closed

Error importing JSONParser #25

tegefaulkes opened this issue Mar 21, 2023 · 10 comments

Comments

@tegefaulkes
Copy link

In our code base when we try to import JSONParser with import { JSONParser } from '@streamparser/json'; we get the following error TS2307: Cannot find module '@streamparser/json' or its corresponding type declarations..

Currently as a work around we are importing it with const jsonStreamParsers = require('@streamparser/json'); which works fine.

My question is, do you have any insights to why the usual import is failing? Or is this likely a problem with the configuration of our project in some way?

Thanks.

@juanjoDiaz
Copy link
Owner

Hi @tegefaulkes ,

Which version of @streamparser/json are you using?
Which bundler are you using (webpack, rollup, esbuild, ...)?

The types are embedded in the package: https://github.com/juanjoDiaz/streamparser-json/blob/main/packages/plainjs/package.json#L8-L15 so there shouldn't be any problem.

You can check in your node_modules folder that the package is installed and the types are where they should be.

You can see here that a bunch of people is using it without a problem.

@CMCDragonkai
Copy link

Our tsconfig specifies "module": "CommonJS".

If we use a simple script like this:

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

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

main();

Then attempt to compile with tsc it gives us this:

[nix-shell:~/Projects/Polykey]$ tsc ./test.ts
test.ts:1:28 - error TS2307: Cannot find module '@streamparser/json' or its corresponding type declarations.

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


Found 1 error in test.ts:1

Current version of @streamparser/json is 0.0.12.

The tsc is 4.9.3.

We use lots of other packages, this is the first we have encountered this problem. Is it because of different package configuration?

@CMCDragonkai
Copy link

We don't use any bundler. It's just tsc.

We're also using swc, but swc does not have the same problem.

@CMCDragonkai
Copy link

Full tsconfig.json is:

{
  "compilerOptions": {
    "outDir": "./dist",
    "tsBuildInfoFile": "./dist/tsbuildinfo",
    "incremental": true,
    "sourceMap": true,
    "declaration": true,
    "allowJs": true,
    "strictNullChecks": true,
    "noImplicitAny": false,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "moduleResolution": "node",
    "module": "CommonJS",
    "target": "ES2022",
    "baseUrl": "./src",
    "paths": {
      "@": ["index"],
      "@/*": ["*"]
    },
    "noEmit": true
  },
  "include": [
    "./src/**/*",
    "./src/**/*.json",
    "./tests/**/*",
    "./scripts/**/*",
    "./benches/**/*"
  ],
  "ts-node": {
    "require": ["tsconfig-paths/register"],
    "transpileOnly": true,
    "swc": true
  }
}

@juanjoDiaz
Copy link
Owner

Hi guys,

Indeed there seems to be an issue in versions after 0.10.
I'll look into it asap.

@tk-o
Copy link

tk-o commented Apr 1, 2023

I have it fixed on my end.

As a hint, I went to the dist/package.json file and removed this part:

  "typesVersions": {
    "*": {
      "*": ["./src/*"]
    }
  },

The typings were immediately matched in my VS Code.

Not sure why the typesVersions prop is an issue, but apparently that's the case.

@CMCDragonkai
Copy link

Cool, are you going to release a new version with the fix?

@juanjoDiaz
Copy link
Owner

Thanks for the hint.

The issue seems caused by a bug in Typescript: microsoft/TypeScript#43133

I'll do a fix asap 🙂

@juanjoDiaz
Copy link
Owner

This is fixed as part of 0.0.13.

Thanks for your patience!

@CMCDragonkai
Copy link

Nice!

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

No branches or pull requests

4 participants