avishayil / react-native-restart

React Native Package With One Purpose: To Restart Your React Native Project
MIT License
941 stars 149 forks source link

Fix TypeScript import path #160

Closed lachenmayer closed 3 years ago

lachenmayer commented 3 years ago

Hi there, the TypeScript path in package.json is incorrect, causing the import to fail with Could not find a declaration file for module 'react-native-restart'. when used from TypeScript.

I've previously had to make this exact fix this in another library too (https://github.com/greentriangle/react-native-leveldb/pull/1), so I believe this is probably an issue with react-native-builder-bob. For now, this fix should solve the import issue in this library though. I will open an issue on the react-native-builder-bob repo too.

Thanks a lot!

lachenmayer commented 3 years ago

Actually this seems to be fixed in the latest react-native-builder-bob. https://github.com/callstack/react-native-builder-bob/issues/140

SaeedZhiany commented 3 years ago

@avishayil

I have this problem too. please review and merge this if it's fix the problem, Thanks

SaeedZhiany commented 3 years ago

@lachenmayer

I applied your changes manually in my project, but I still, have a TS error.

image

is it working perfectly on your project?

update

when I moving the file index.d.ts to the root directory of the repository and change the path in package.json to "types": "index.d.ts",, the error is gone. @avishayil please consider it too before merging.

avishayil commented 3 years ago

I'll review it this week, sorry for the time it takes...

Adnan-Bacic commented 3 years ago

im getting the same error but with JS instead of TS. do you know if its the same problem?

SaeedZhiany commented 3 years ago

@avishayil is there any progress on this? Thanks for your time.

TheWirv commented 3 years ago

I encountered the same problem, and @lachenmayer's fix is an easy one that works. :) I wanted to second the notion to approve this PR because this is an issue that we also cannot patch-package unfortunately, due to it concerning the package.json file. :/

SaeedZhiany commented 3 years ago

@TheWirv

have you encountered the problem I mentioned in this comment after applying @lachenmayer's fix?

TheWirv commented 3 years ago

@TheWirv

have you encountered the problem I mentioned in this comment after applying @lachenmayer's fix?

@SaeedZhiany No, it works perfectly fine for me, sorry. :(

SaeedZhiany commented 3 years ago

What typescript version you are using?

TheWirv commented 3 years ago

What typescript version you are using?

4.2.4

SaeedZhiany commented 3 years ago

I tried that version, it seems the problem is not related to the typescript version. However, the update section in this comment is also resolving my problem, I hope @avishayil review and fix the issue soon.

SaeedZhiany commented 3 years ago

I don't know why but I just figured out that the structure of the repository is pretty different from what we are installing.

installed package sadsa
image image

there is no lib directory in the repository and I'm wondering how it has been generated.

However, I found a way to resolve the TS error I reported in this comment. when I replace the content of the file /lib/typescript/index.d.ts with the code below, the problem is resolving.

declare module 'react-native-restart' {
    type RestartType = {
        Restart(): void;
    };
    const RNRestart: RestartType;
    export default RNRestart;
}

I wanted to make a PR for this to integrate @lachenmayer PR and my solution to resolve typing problems but as I said early, I couldn't the file in the repository to modify.

@avishayil please apply these changes soon, I really need them in my project. Thanks

SaeedZhiany commented 3 years ago

@avishayil did you read my comments above?

avishayil commented 3 years ago

Hi @SaeedZhiany the lib folder is create using the bob build command which packages and prepares the artifact to be deployed to npm.

SaeedZhiany commented 3 years ago

is there any way to solve my problem too? the change of this PR does not work for me as I said before.

xiankuncheng commented 3 years ago

Thank you all for the effort to solve this issue for the community. I've met the same issue this week as well, and figured out it's been fixed already, that's amazing.

Do we have any plan to release a new version to npm soon? Since the latest version on npm (0.0.22) is still with the wrong type path in the package.json file. Appreciate all the help 🙏

badsyntax commented 3 years ago

@avishayil can we get a new release please?

badsyntax commented 3 years ago

While we wait for a release i'm patching this issue by creating a new file called react-native-restart.d.ts with the following contents:

declare module 'react-native-restart' {
  type RestartType = {
    Restart(): void;
  };
  const _default: RestartType;
  export default _default;
}
avishayil commented 3 years ago

Sure. I'm waiting for #167 to release a new version with Windows support.

barbieri commented 3 years ago

would you mind a new release? 0.0.22 is still wrong :-/

crutchcorn commented 3 years ago

+1 to @barbieri's comment. 0.0.22 uses the wrong import path, despite the code in the repo being correct

vonovak commented 3 years ago

@avishayil would you be so kind and release the new version? There is no need to wait for anything; thank you! :)

angelos3lex commented 2 years ago

@avishayil Can you please release master on npm ? This is blocking us from updating the lib, as its was not a prob back in 0.0.17. Would love to avoid suggested workarounds too, since this is fixed already :)

pedrohff360 commented 2 years ago

Do we have some expectation about the next release? :)

bombillazo commented 2 years ago

Following up to see when this will get release.