2019年3月11日月曜日

TypeScriptでビルドしようとしたけどVariable 'require' must be of type 'NodeRequire', but here has type 'ReactNativeRequireFunction'ってエラーが出たのでその解決方法的なお話

  • このエントリーをはてなブックマークに追加

typescriptでreact-native-simple-twitterを作り直してて、途中までビルドできてたのに突然ビルドできなくなるっていう。
多分jest関連のpackageを色々と入れたからかなぁみたいな感じではあるんだけど。

node_modules/@types/react-native/index.d.ts:9302:9 - error TS2403: Subsequent variable declarations must have the same type. Variable 'require' must be of type 'NodeRequire', but here has type 'ReactNativeRequireFunction'.
とりあえずこんな感じのエラーが出てきた。
割と悩んだので今日はその解決法をば。

tsconfig.jsonにtypesを加えただけ。

{
  "compilerOptions": {
    ...
    "types": [
      "react-native"
    ]
  }
}

requireがNodeRequireだけどReactNativeRequireFunctionで云々ってことだったので、とりあえずtypesにreact-nativeを加えてあげたらエラーなくなった。
requireがnodeとreact-nativeでごちゃごちゃになってるからかもね。
今回作っているものはreact-native用のライブラリだったからreact-nativeにしておいた。

typescriptの設定周りなかなかややこしいこと多いよね的なみたいな感じ。

0 件のコメント:

コメントを投稿

Adsense