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 TS2665: Invalid module name in augmentation in jest/async-storage-mock #746

Closed
1 of 5 tasks
fqborges opened this issue Feb 9, 2022 · 14 comments · Fixed by #805
Closed
1 of 5 tasks

error TS2665: Invalid module name in augmentation in jest/async-storage-mock #746

fqborges opened this issue Feb 9, 2022 · 14 comments · Fixed by #805
Labels
bug Something isn't working

Comments

@fqborges
Copy link

fqborges commented Feb 9, 2022

What happened?

Just upgraded to 1.16.0, my typescript builds started to error with:

node_modules/@react-native-async-storage/async-storage/lib/typescript/index.d.ts:6:16 - error TS2665: Invalid module name in augmentation. Module '@react-native-async-storage/async-storage/jest/async-storage-mock' resolves to an untyped module at '[...]/node_modules/@react-native-async-storage/async-storage/jest/async-storage-mock.js', which cannot be augmented.

6 declare module '@react-native-async-storage/async-storage/jest/async-storage-mock' {

Version

1.16.0

What platforms are you seeing this issue on?

  • Android
  • iOS
  • macOS
  • Windows
  • web

System Information

System:
    OS: Windows 10 10.0.22000
    CPU: (8) x64 AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx
    Memory: 6.79 GB / 17.88 GB
  Binaries:
    Node: 14.17.1 - ~\AppData\Local\Temp\yarn--1644419667475-0.14216515503697358\node.CMD
    Yarn: 1.22.5 - ~\AppData\Local\Temp\yarn--1644419667475-0.14216515503697358\yarn.CMD
    npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Version     2020.3.0.0 AI-203.7717.56.2031.7935034
    Visual Studio: 16.11.32002.261 (Visual Studio Community 2019)
  Languages:
    Java: 1.8.0_282 - C:\Program Files\AdoptOpenJDK\jdk-8.0.282.8-hotspot\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.66.4 => 0.66.4
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to Reproduce

yarn install "@react-native-async-storage/[email protected]
yarn tsc

@fqborges fqborges added the bug Something isn't working label Feb 9, 2022
@tido64
Copy link
Member

tido64 commented Feb 9, 2022

Hi @fqborges, do you know which version of TypeScript you're using? And do you have a repo where this reproduces? It's odd that we didn't see this during testing.

Edit: FWIW, I imported 1.16 in a project of ours and don't see this error message. We're using TypeScript 4.5.5.

@fqborges
Copy link
Author

fqborges commented Feb 10, 2022

Wow, I cant reproduce in a fresh react-native app. I will try again later.

I will extract a mre from my private repo.

which version of TypeScript you're using?
[email protected]

Thanks.

@chintannp
Copy link

I am getting the same error.

@tststs
Copy link

tststs commented Feb 15, 2022

same issue here since upgrading from ^1.15 to ^1.16.

Could not find a declaration file for module '@react-native-async-storage/async-storage/jest/async-storage-mock'. '/.../node_modules/@react-native-async-storage/async-storage/jest/async-storage-mock.js' implicitly has an 'any' type.
  If the '@react-native-async-storage/async-storage' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module '@react-native-async-storage/async-storage/jest/async-storage-mock';`

@JimTeva
Copy link

JimTeva commented Feb 19, 2022

I confirm, the error appears with 1.16.
Here is my setup:

  • react native 0.65.1
  • typescript 4.5.5
    If I use @react-native-async-storage/[email protected], there is no error.

@tido64
Copy link
Member

tido64 commented Feb 19, 2022

Do you have a public repo where this occurs? As I mentioned above, I cannot repro this error.

Edit: Also, please make sure you retry after cleaning out caches and the like. OP was also unable to repro in a fresh RN app.

@Elias-Graf
Copy link

Elias-Graf commented Feb 23, 2022

I had this error happen on version 15, and upgraded to 16 hoping it will fix it. It did not. I'll see if I can figure out the issue.

@Elias-Graf
Copy link

Elias-Graf commented Feb 23, 2022

I just noticed that I don't have the issue that the author has. BUT the issue that the author has seems to come from trying to solves this.

I'm getting:

error TS7016: Could not find a declaration file for module '@react-native-async-storage/async-storage/jest/async-storage-mock'. '/var/app/node_modules/@react-native-async-storage/async-storage/jest/async-storage-mock.js' implicitly has an 'any' type.
Try npm i --save-dev @types/react-native-async-storage__async-storage if it exists or add a new declaration (.d.ts) file containing declare module '@react-native-async-storage/async-storage/jest/async-storage-mock';

If I then add declare module '@react-native-async-storage/async-storage/jest/async-storage-mock'; in my code, I get:

error TS2665: Invalid module name in augmentation. Module '@react-native-async-storage/async-storage/jest/async-storage-mock' resolves to an untyped module at '/var/app/node_modules/@react-native-async-storage/async-storage/jest/async-storage-mock.js', which cannot be augmented.

So... the original issue probably isn't the root cause.

It's also really weird, I found the initial import to sometimes work, and suddenly stop (in new project). Or it could be a weird caching thing, from VSCode or whatever. But the following docker container reproduces my issue, every time (at least for me).

Ah, and it is noteworthy to say, that I do not put the mock into the jest setup file, like stated here: https://react-native-async-storage.github.io/async-storage/docs/advanced/jest/#with-jest-setup-file. I just import it in the tests that require the mock.

Instructions

Create a random directory and place the following files inside it:

index.ts

import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';

function test() {
  mockAsyncStorage();
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}

package.json

{
  "name": "react-native-async-storage-mock-test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.16.1",
    "typescript": "^4.5.5"
  },
  "description": ""
}

Dockerfile

FROM node:16-alpine

WORKDIR /var/app

COPY package.json tsconfig.json index.ts ./

RUN npm install

CMD ["npx", "tsc", "--noEmit"]

Now just build and run that container. (inside the created directory: docker build ., after that ran there should be an id at the bottom (successfully built <id>), docker run <id by the previous command>).

@danilobuerger
Copy link
Contributor

Using

diff --git a/node_modules/@react-native-async-storage/async-storage/lib/typescript/index.d.ts b/node_modules/@react-native-async-storage/async-storage/lib/typescript/index.d.ts
index 82f4649..4847a4a 100644
--- a/node_modules/@react-native-async-storage/async-storage/lib/typescript/index.d.ts
+++ b/node_modules/@react-native-async-storage/async-storage/lib/typescript/index.d.ts
@@ -3,8 +3,3 @@ import type { AsyncStorageHook, AsyncStorageStatic } from './types';
 export { useAsyncStorage } from './hooks';
 export type { AsyncStorageStatic } from './types';
 export default AsyncStorage;
-declare module '@react-native-async-storage/async-storage/jest/async-storage-mock' {
-    export function useAsyncStorage(key: string): AsyncStorageHook;
-    const AsyncStorageLib: AsyncStorageStatic;
-    export default AsyncStorageLib;
-}

is my workaround until this is fixed

@github-actions
Copy link

github-actions bot commented May 6, 2022

This issue has been marked as stale due to inactivity. Please respond or otherwise resolve the issue within 7 days or it will be closed.

@github-actions github-actions bot added the Stale label May 6, 2022
@SimenB
Copy link

SimenB commented May 6, 2022

Expo 45 is out which uses this version, so just hit it.

If people are having issues reproducing, make sure skipLibCheck is false

@tido64
Copy link
Member

tido64 commented May 13, 2022

Hi folks, sorry it took so long to get back to you on this. Like I said earlier, I couldn't repro this locally. However, I did get a different error when I imported the module directly in source. Please check out #805 and let me know if it fixes the issue for you.

@krizzu
Copy link
Member

krizzu commented May 18, 2022

🎉 This issue has been resolved in version 1.17.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@SimenB
Copy link

SimenB commented May 18, 2022

Can confirm it works fine now, thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants