React Native:纱线工作空间下的捆绑器无法解析`styled-components / native`

时间:2020-02-16 08:32:19

标签: reactjs react-native yarnpkg styled-components yarn-workspaces

我最近使用纱线工作区和一个现有的react native项目迁移到了monorepo。现在,我在“ packages /”下有一个名为“ timeylo”的react本机项目,该项目的react-native依赖关系不会因纱线而挂起。

我捆绑JavaScript时遇到的错误:

error: bundling failed: Error: Unable to resolve module `styled-components/native` from `/Users/sunhe/Documents/Projects/issue/issue-repo/packages/timeylo/src/app.tsx`: Module `styled-components/native` does not exist in the Haste module map or in these directories:
  /Users/sunhe/Documents/Projects/issue/issue-repo/node_modules/styled-components

我有一个重播错误的仓库:https://github.com/bidiu/issue-repo

您需要做的是:

  • yarn的根源
  • cd packages/timeylo
  • yarn start启动捆绑程序
  • 在另一个终端中,yarn react-native run-ios(或使用Xcode)。

您应该在捆绑程序会话下看到错误。

如果需要,可以提供react-native info的更多信息:)

System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
    Memory: 207.65 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.15.3 - /var/folders/dl/9r8h7nj57ps6h4t4jpwd_1kh0000gn/T/yarn--1581841642552-0.27345581007574116/node
    Yarn: 1.21.1 - /var/folders/dl/9r8h7nj57ps6h4t4jpwd_1kh0000gn/T/yarn--1581841642552-0.27345581007574116/yarn
    npm: 6.10.3 - ~/.nvm/versions/node/v10.15.3/bin/npm
    Watchman: 4.9.0 - /opt/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.5 => 0.60.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1

非常感谢您!

3 个答案:

答案 0 :(得分:1)

对于纱线:

yarn add styled-component

对于 npm :

npm install --save styled-component

答案 1 :(得分:0)

npm install styled-components --save

尝试以上一项,它将起作用

答案 2 :(得分:0)

我在打开一个新终端并再次尝试解决它时遇到了同样的问题:)“npm install --save styled-components”也应该解决它。