GeekyAnts / react-native-zebra-bluetooth-printer

MIT License
24 stars 15 forks source link

Hi, I need to use react-native-zebra-bluetooth-printer with my application which is expo managed, I got this error [Unhandled promise rejection: TypeError: Cannot read property 'init' of undefined] #18

Open ImanSharabatiHM opened 1 year ago

ImanSharabatiHM commented 1 year ago
### Tasks
ImanSharabatiHM commented 1 year ago

"dependencies": { "@config-plugins/react-native-blob-util": "^5.0.0", "@config-plugins/react-native-pdf": "^5.0.0", "@expo-google-fonts/cairo": "^0.2.3", "@hashiprobr/expo-pdf-reader": "^1.0.8", "@react-native-async-storage/async-storage": "1.17.11", "@react-native-community/datetimepicker": "6.7.3", "@react-native-community/netinfo": "9.3.7", "@react-native-masked-view/masked-view": "0.2.8", "@react-navigation/drawer": "^6.6.2", "@react-navigation/native": "^6.1.6", "@react-navigation/stack": "^6.3.16", "@types/react": "~18.0.27", "apisauce": "^3.0.0", "expo": "~48.0.18", "expo-asset": "~8.9.1", "expo-auth-session": "~4.0.3", "expo-av": "~13.2.1", "expo-blur": "~12.2.2", "expo-calendar": "~11.1.1", "expo-camera": "~13.2.1", "expo-constants": "~14.2.1", "expo-dev-client": "~2.2.1", "expo-device": "~5.2.1", "expo-image-picker": "~14.1.1", "expo-intent-launcher": "~10.5.2", "expo-linear-gradient": "~12.1.2", "expo-linking": "~4.0.1", "expo-location": "~15.1.1", "expo-network": "~5.2.1", "expo-notifications": "~0.18.1", "expo-print": "~12.2.1", "expo-random": "~13.1.1", "expo-secure-store": "~12.1.1", "expo-sharing": "~11.2.2", "expo-sms": "~11.2.1", "expo-splash-screen": "~0.18.2", "expo-sqlite": "~11.1.1", "expo-status-bar": "~1.4.4", "expo-task-manager": "~11.1.1", "expo-web-browser": "~12.1.1", "fbjs": "^3.0.5", "formik": "^2.4.0", "jwt-decode": "^3.1.2", "jwt-encode": "^1.0.1", "lottie-react-native": "5.1.4", "moment": "^2.29.4", "react": "18.2.0", "react-native": "0.71.8", "react-native-3dcube-navigation": "^1.0.5", "react-native-action-button": "^2.8.5", "react-native-add-calendar-event": "^4.2.0", "react-native-ble-plx": "^2.0.3", "react-native-blob-util": "^0.18.2", "react-native-collapsible": "^1.6.1", "react-native-easy-toast": "^2.3.0", "react-native-expo-image-cache": "^4.1.0", "react-native-gesture-handler": "~2.9.0", "react-native-linear-gradient": "^2.6.2", "react-native-modal": "^13.0.1", "react-native-modal-datetime-picker": "^15.0.1", "react-native-modalbox": "^2.0.2", "react-native-modalize": "^2.1.1", "react-native-pager-view": "6.1.2", "react-native-paper": "^5.8.0", "react-native-pdf": "^6.6.2", "react-native-progress": "^5.0.0", "react-native-reanimated": "~2.14.4", "react-native-redash": "^18.1.0", "react-native-safe-area-context": "4.5.0", "react-native-skeleton-placeholder": "^5.2.4", "react-native-stopwatch-timer": "^0.0.21", "react-native-svg": "13.4.0", "react-native-swipe-gestures": "^1.0.5", "react-native-tab-view": "^3.5.1", "react-native-webview": "11.26.0", "react-native-zebra-bluetooth-printer": "^1.0.12", "realm": "^11.10.1", "rn-pdf-reader-js": "^4.1.1", "typescript": "^4.9.4", "yup": "^1.2.0" }, It seems that the package is incompatible with my dependencies "react": "18.2.0", "react-native": "0.71.8", Can you update the package to be compatible with my project?

wesvh commented 10 months ago

You got it?

syahbes commented 9 months ago

same here.. could not made this work on my react native expo app even when I tried to use $npm run prebuild or add d.ts file

wesvh commented 9 months ago

I build this package (use other github repository base, but integrate this funcionality) https://www.npmjs.com/package/react-native-bluetooth-zebra-printer-qv

Only need follow this tutorial (only the android package own, because i fix the library for prevent edit in the node_modules) https://www.youtube.com/watch?v=BXbseqogkMQ

syahbes commented 9 months ago

I build this package (use other github repository base, but integrate this funcionality) https://www.npmjs.com/package/react-native-bluetooth-zebra-printer-qv

Only need follow this tutorial (only the android package own, because i fix the library for prevent edit in the node_modules) https://www.youtube.com/watch?v=BXbseqogkMQ

Thank you! I followed the tutorial and now I can see the printer via the Bluetooth manager

I also installed : npm i react-native-bluetooth-zebra-printer-qv

and now how to print to my Zebra printer? need to print simple text like a 'hello world'

I added a zpl for exemple test_label.zpl.txt

wesvh commented 9 months ago

In my research to also make my zebra work, I discovered that there are multiple models of thermal printers, and some are configured as CPL and not as ZPL, for this the zebra have an app in the playstore called printer setup, there you link your bluetooth printer and in the configuration section you should do something like "print language" or something like that

syahbes commented 9 months ago

Thank you for the fast reply! yes you are right the file can be zpl or cpl but how to send it to the printer?

wesvh commented 9 months ago

I'm just active right now xd

It's simple, you just use the same method that is in this repository RNZebraBluetoothPrinter.print(deviceAddress,zpl).then((res) => { //do something with res })

The only difference is that you will extract the RNZebraBluetoothPrinter method

From react-native-bluetooth-zebra-printer-qv

like that import { RNZebraBluetoothPrinter } from "react-native-bluetooth-zebra-printer-qv";

And you pass it the deviceAddress, which you get (Do not link it from the BluetoothManager of the tutorial, just extract the macAddress, and pass it as a property to the function)

image

syahbes commented 9 months ago

Thank you!! I will try that

syahbes commented 9 months ago

Lifesaver! Your youtube video + npm library got me printing to my Zebra zd230 from RN Expo. THANKS !

syahbes commented 7 months ago

Hi :) I worked well for the past months but now when I tried to run the app got this error:

 ERROR  TypeError: Cannot set property 'DIRECTION' of null, js engine: hermes

do you know how I can solve it?

this is from the index.js in node_moduls/react-native-zebbra-printer-qv

 import { NativeModules } from "react-native";
const {
  BluetoothManager,
  BluetoothEscposPrinter,
  BluetoothTscPrinter,
  RNZebraBluetoothPrinter,
} = NativeModules;

BluetoothTscPrinter.DIRECTION = {
  FORWARD: 0,
  BACKWARD: 1,
};
syahbes commented 6 months ago

Hi :) I worked well for the past months but now when I tried to run the app got this error:

 ERROR  TypeError: Cannot set property 'DIRECTION' of null, js engine: hermes

do you know how I can solve it?

this is from the index.js in node_moduls/react-native-zebbra-printer-qv

import { NativeModules } from "react-native";
const {
 BluetoothManager,
 BluetoothEscposPrinter,
 BluetoothTscPrinter,
 RNZebraBluetoothPrinter,
} = NativeModules;

BluetoothTscPrinter.DIRECTION = {
 FORWARD: 0,
 BACKWARD: 1,
};

Fixed.. The error occurred because I tried running it in the Expo Go app instead of the dev build on my mobile.