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

v1.3.0: TypeScript issue when importing tiny-invariant from an CJS codebase and "moduleResolution" is set to "node16" #151

Closed
pkerschbaum opened this issue Sep 28, 2022 · 4 comments

Comments

@pkerschbaum
Copy link
Contributor

πŸ•— Version & Regression Information

1.3.0

⏯ Playground Link

https://stackblitz.com/edit/node-cwmfq6

  1. Run npm install.
  2. Run tsc compilation via npm run build. The error occurs.

Problem

If tiny-invariant is used from an TypeScript CJS package with moduleResolution node16, this means:

  • "type" in package.json is not set or set to commonjs
  • and "moduleResolution": "node16" set in tsconfig.json

...then TypeScript cannot find the types:

❯ npm run build
$ tsc
src/test.ts:1:23 - error TS7016: Could not find a declaration file for module 'tiny-invariant'. '/home/projects/node-cwmfq6/node_modules/tiny-invariant/dist/tiny-invariant.cjs.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/tiny-invariant` if it exists or add a new declaration (.d.ts) file containing `declare module 'tiny-invariant';`

1 import invariant from 'tiny-invariant';
                        ~~~~~~~~~~~~~~~~


Found 1 error in src/test.ts:1

Reason

See #150.

@pkerschbaum pkerschbaum changed the title v1.3.0: TypeScript issue when importing tiny-invariant from an CJS codebase and "moduleResolution": "node16" v1.3.0: TypeScript issue when importing tiny-invariant from an CJS codebase and "moduleResolution" is set to "node16" Sep 28, 2022
@pkerschbaum pkerschbaum changed the title v1.3.0: TypeScript issue when importing tiny-invariant from an CJS codebase and "moduleResolution" is set to "node16" v1.3.0: TypeScript issue when importing tiny-invariant from an CJS codebase and "moduleResolution" is set to "node16" Sep 28, 2022
@alexreardon
Copy link
Owner

@pkerschbaum do you think I should deprecate 1.3.0 on npm?

@pkerschbaum
Copy link
Contributor Author

Yes let's do that...

@alexreardon
Copy link
Owner

This issue has been resolved in 1.3.1 -> https://stackblitz.com/edit/node-bs8cec?file=package.json

@alexreardon
Copy link
Owner

Fixed by #150

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

2 participants