TNS-Core-Modules dependency conflict with Nativescript 8 - nativescript

I inherited some Nativescript code that was working fine for iOS but failing for Android.
My environment is:
android sdk 11
jdk 14
node 16
My package.json dependencies are:
"dependencies": {
"#nativescript/core": "~8.1.1",
"#nativescript/firebase": "^11.1.3",
"#nativescript/theme": "~3.0.1",
"nativescript-vue": "~2.9.0",
"tns-core-modules": "^6.5.27"
},
"devDependencies": {
"#nativescript/android": "8.1.1",
"#nativescript/ios": "8.1.0",
"#nativescript/webpack": "~5.0.0",
"nativescript-vue-template-compiler": "~2.9.0",
"sass": "^1.32.8"
}
The issue seems to be arising from the implementation of push notifications where a requirement is grabbing the UUID of the device.
In the initial version of the code, they were using a library called "nativescript-uuid". Using that library and targeting iOS seemed to work fine. However, when targeting Android, I would get an error that it could not find something like " cant find module tns-core-modules/platform....". I looked into tns-core-modules and saw it wasn't in my node_modules folder, and I added it as a dependency using tns plugin add "tns-core-modules". That removed that specific error but introduced a new one about conflicting class names:
Warning: there already is an extend called com.tns.FragmentClass.
Warning: The static binding generator will generate extend from:vendor.js implementation
java.io.IOException: File already exists. This may lead to undesired behavior.
Please change the name of one of the extended classes.
File:C:<APP DIRECTORY>\platforms\android\app\src\main\java\com\tns\FragmentClass.java
Class: com.tns.FragmentClass
at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:112)
at org.nativescript.staticbindinggenerator.Main.main(Main.java:55)
Before I go down a rabbit hole of google searches, I was wondering if anybody had any idea why this would be failing in the first place and if there were any suggestions on how to resolve the issue.

That plugin hasn't been updated in some time. There's a fork, #kefah/nativescript-uuid/, that promotes itself as being NativeScript 8 compatible.

Related

Duplicate "graphql" modules cannot be used at the same time

Good morning/afternoon stackoverflow. I'm using an npm package called #graphql-codegen/cli to generate type definitions/utilites for my GraphQL schema. Recently, I've been encountering an error each time I try to run graphql-codegen command/script. This is the error that I get
"Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results."
...
"Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed."
I'm fairly certain this issue is with my environment, not my project. I attempted to create a brand new project from scratch and still received the same error. Here are the things I've tried
Reinstalling node_modules
Using the resolutions property in package.json
Using different versions of the graphql/graphql-cli packages
Completely wiping out my global npm packages
I've spent the last couple of days attempting to resolve this error, but I'm all out of ideas. Any thoughts or recommendations are much appreciated. Also, below is a link to a codesandbox that contains the relevant files
https://codesandbox.io/s/graphql-codegen-cli-example-qq5cj
I had the same problem with codegen.
src/generated/graphql.tsx
Error: Cannot use GraphQLObjectType "FieldError" from another module or realm.
Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.
https://yarnpkg.com/en/docs/selective-version-resolutions
Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
running codegen.yml
overwrite: true
schema: "http://localhost:4001/graphql"
documents: "src/graphql/**/*.graphql"
generates:
src/generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-urql"
I think i had conflicting packages. Removing "urql", which i think caused the problem, and reinstalling it solved the error.
yarn run v1.22.17
$ graphql-codegen --config codegen.yml
√ Parse configuration
√ Generate outputs
with package.json
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"gen": "graphql-codegen --config codegen.yml"
},
"dependencies": {
"#chakra-ui/icons": "^1.0.0",
"#chakra-ui/react": "^1.8.5",
"#emotion/react": "^11.0.0",
"#emotion/styled": "^11.0.0",
"formik": "^2.2.9",
"framer-motion": "^4.0.3",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"graphql": "^16.3.0",
"urql": "^2.2.0"
},
"devDependencies": {
"#graphql-codegen/cli": "^2.6.2",
"#graphql-codegen/typescript": "2.4.5",
"#graphql-codegen/typescript-operations": "2.3.2",
"#graphql-codegen/typescript-urql": "^3.5.3",
"#graphql-codegen/urql-introspection": "^2.1.1",
"#types/node": "^17.0.21",
"graphql-tag": "^2.12.6",
"typescript": "^4.5.5"
}
}
You can edit your package.json as needed. Delete the file 'yarn.lock', 'package-lock.json' and the folder 'node_modules' to clear your dependencies. And run 'npm install' / 'yarn install' to reinstall your dependencies.
Have fun!

Can't find RCTPushNotification.xcodeproj

I'd like to use the file RCTPushNotification.xcodeproj inside the directory node_modules/react-native/Libraries/PushNotificationIOS, to add it in my Libraries folder in order to manage iOS push notifications. I'm following this tutorial: https://www.pubnub.com/blog/react-native-push-notifications-ios-android/.
The problem is that I can't find it, even after deleting node_modules and executing npm install && react-native link.
Here is my package.json dependencies, but I don't think that a package could modify my directory:
{
"dependencies": {
"#dudigital/react-native-zoomable-view": "^1.0.14",
"firebase": "^6.5.0",
"pubnub": "^4.27.0",
"pubnub-react": "^1.3.2",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-cli": "^2.0.1",
"react-native-fast-image": "^7.0.2",
"react-native-fs": "^2.16.2",
"react-native-gesture-handler": "^1.5.0",
"react-native-image-picker": "^0.28.0",
"react-native-optimized-flatlist": "^1.0.4",
"react-native-push-notification": "^3.1.9",
"react-native-view-shot": "^3.0.2",
"react-navigation": "^3.13.0",
"react-redux": "^7.1.3",
"redux": "^4.0.4",
"rn-fetch-blob": "^0.11.2"
}
Here are the only files I can see on this directory:
NativePushNotificationManager.js
RCTPushNotificationManager.h
RCTPushNotificationManager.m
React-RCTPushNotification.podspec
Knowing that RCTPushNotificationManager.m and RCTPushNotificationManager.h should be inside my xCode project, I tried to put the entire PushNotificationIOS folder in my Libraries folder, but it doesn't seems to work because there is not the necessary Products folder inside of an xCode project.
I also tried to put each of this files in my Libraries folder, but Xcode doesn't consider them as xCode projects (not very surprising).
This issue doesn't seem to have been encountered earlier.
After just spending a lot of time and effort on push notifications, I recommend you look into OneSignal push notifications. Saved me a lot of time.
However, you should be able to find the .xcodeproj here: https://github.com/react-native-community/react-native-push-notification-ios/tree/master/ios

Reuse package.json version within file

I have a project which uses dependency having having version same as that of the project. So I would like to change the version only in one place and write something like below this in my package.json
{
"name": "my-child-app",
"version": "1.2.3",
"description": "My Application",
"dependencies": {
"my-parent-app": %npm_package_version%
}
}
Basically the child app is always supposed to have version in sync with the parent app. So any approach where I will have to change only one line (instead of two in usual scenario) when I have to upgrade to a newer parent-app would suffice.
Note: I am using frontend-maven-plugin to build the project as child-app is a module of Java Project. parent-app is also built in a same way but they are not in the same code repository so file referencing cannot be used.

Nativescript: TypeError: Invalid Version: 1.?2.0

I'm getting the error while installing the plugin.
TypeError: Invalid Version: 1.?2.0
I've created the plugin for NativeScript.
Here is how my package.json looks like.
{
"name": "nativescript-toaster",
"version": "1.0.1",
"main": "index.js",
"nativescript": {
"platforms": {
"android": "1.​2.0"
}
}
}
As described in some forums I've tried to remove the android entries from package.json of NS projects, and clean cache npm cache clean. But as I add android platform tns platform add android it comes again.
Please share if you've any idea about this.
Thanks Guys
I was getting the same error. In my case, I was trying to include iOS and Android native code; I tried changing it like this: "1.3.0" , and the error disappeared.

Cannot find module after creating and adding plugin in Nativescript

Using the latest version of Nativescript I've created a plugin as per the documentation and after running tns plugin add ../nativescript-keychain I get the message Successfully installed plugin nativescript-keychain.
I can also see that it's been added to the node_modules directory of my app but require("nativescript-keychain") doesn't work as I get the error Cannot find module 'nativescript-keychain'
My plugin package.json looks like
{
"name": "nativescript-keychain",
"version": "0.0.1",
"nativescript": {
"platforms": {
"ios": "2.2.1"
}
}
}
There are several reasons why this might occur; it would be helpful if you provided a repo to see all the code.
package.json doesn't have a link to the source, typically you have a main: "somefile" key.
Did you do tns run ios --emulator after you installed the plugin, you have to rebuild the app before it will take effect, plugins can't be synced via livesync...
Is the code TypeScript or JavaScript, if it is TypeScript it needs to be transpiled to JS before you can add it to your demo application. TNS will NOT compile any TS code in the plugins. Plugins have to ship with the final JS code.
You need typings for TS to use the auto-complete and not throw warnings about what methods are available.

Resources