clipboard: setString doesn't work

Environment

 Expo CLI 3.27.4 environment info:
    System:
      OS: Windows 10 10.0.20206
    Binaries:
      Node: 14.10.1 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.19.2 - F:\Programy\yarm\bin\yarn.CMD
      npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
    npmPackages:
      expo: ^38.0.10 => 38.0.10
      react: ^16.11.0 => 16.11.0
      react-dom: ^16.11.0 => 16.11.0
      react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2
      react-native-web: ^0.11.7 => 0.11.7
    Expo Workflow: managed

Platforms

iOS, not sure about Android, it is possibly (and probably) also affected.

Versions

  • iOS: 14 beta 7
  • react-native: 0.62
  • react: 16.11.0

Description

When trying to set a string to the clipboard, it is denied and errors out:

TypeError: null is not an object (evaluating 'NativeClipboard_1.setString')

Reproducible Demo

Clipboard.setString("Test"); // Errors out

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 13
  • Comments: 32 (3 by maintainers)

Most upvoted comments

I have the same issue (expo SDK 38). I ended up reverting to clipboard from react-native for now. import { Clipboard } from 'react-native'

updated: You can use import * as Clipboard from 'expo-clipboard' now. I’m usgin SDK 43.

I had the same problem on Android. Solved uninstalling the app and reinstalling it.

currently managed workflow for expo does not support this clipboard module. Please continue using import {Clipboard} from 'react-native' for now until the support is added to expo.

This module should work for bare workflow of expo and regular react-native via react-native-cli sorry about the inconvenience!

Same here on Expo SDK 38 + 39 and @react-native-community/clipboard: ^1.2.3

Solved it by using @foloinfo solution by using import { Clipboard } from 'react-native'

There is honestly nothing I can do about using this package on a managed workflow of expo, as managed workflow of expo has predetermined sets of native modules it can use and this package isn’t one of them.

Please use import {Clipboard} from 'react-native' for managed workflow of expo.

don’t think it’s the library issue try to clean your project(reset metro bundler cache, delete build folder) and do fresh npm install and pod install. That worked for me!

I have the same issue, I solved it this way: import {useClipboard} from '@react-native-community/clipboard';

Same here on Expo SDK 38 + 39 and @react-native-community/clipboard: ^1.2.3

Solved it by using @foloinfo solution by using import { Clipboard } from 'react-native'

The only issue with that method is it has been declared as deprecated even though it still works. Also, it points them here to where things are broken… image

cd ios && pod install then yarn start --reset-cache then remove the app from your simulator or phone and rebuild/reinstall it

the solution is as simple as: import Clipboard from '@react-native-community/clipboard' instead of import { Clipboard } from '@react-native-community/clipboard'

Same issue here, using deprecated version from “react-native” temporarily solves my issue.

import { Clipboard } from "react-native"

I solved it

cd ios && pod install

The same problem with v1.5.1 on android and web app. I tried to use Clipboard.setString and hook realization, both have this problem.

I had the same issue with Android. Weird enough I had to do a pod install: cd ios && pod install && cd ../ after that, I ran react-native run-android and it worked.

I’m getting the same issue on iOS 13.6, react-native 0.59 - any workaround?

don’t think it’s the library issue try to clean your project(reset metro bundler cache, delete build folder) and do fresh npm install and pod install. That worked for me!

Just solved the issue by restart the metro bundler. i.e. re-run react-native start. Thank you 😃

Hi, Need to release the app so cannot go with deprecated one, please fix this issue ASAP 🙏