Nativescript-cli: Can't build app if both itself and its dependency have a dependency on tns-core-modules

Created on 24 Mar 2019  ยท  4Comments  ยท  Source: NativeScript/nativescript-cli

Environment

  • CLI: 5.2.4
  • Cross-platform modules: 5.2.2
  • Android Runtime: 5.2.1
  • iOS Runtime: 5.2.0
  • Plugin(s): none

Describe the bug

I'm making a React renderer for NativeScript (try to stay calm). It depends upon tns-core-modules. However, when I install this React renderer as a dependency of a sample app, when building the sample app (whether with or without the --bundle flag), Xcode finds duplicates of tns-core-modules and thus tns-core-modules-widgets. This could be related to the webpack config (which is using the defaults from tns create sample --tsc)..?

# Where 'sample' is the app that consumes the React renderer library 
cd sample
tns run ios --clean

Typescript typings conflicts:

Skipping node_modules folder! Use the syncAllFiles option to sync files from this folder.
Searching for devices...
Found peer TypeScript 3.1.6
../react-nativescript/node_modules/tns-core-modules/module.d.ts(69,5): error TS2300: Duplicate identifier 'markup'.
../react-nativescript/node_modules/tns-core-modules/module.d.ts(70,5): error TS2300: Duplicate identifier 'script'.
../react-nativescript/node_modules/tns-core-modules/module.d.ts(71,5): error TS2300: Duplicate identifier 'style'.
../react-nativescript/node_modules/tns-core-modules/tns-core-modules.d.ts(4,1): error TS6200: Definitions of the following identifiers conflict with those in another file: "audio", "beacon", "cspreport", "download", "embed", "eventsource", "favicon", "fetch", "font", "form", "frame", "hyperlink", "iframe", "image", "imageset", "import", "internal", "location", "manifest", "object", "ping", "plugin", "prefetch", "script", "serviceworker", "sharedworker", "subresource", "style", "track", "video", "worker", "xmlhttprequest", "xslt", HeaderInit, WeakRef
../react-nativescript/node_modules/tns-core-modules/tns-core-modules.d.ts(5,5): error TS2432: In an enum with multiple declarations, only one declaration can omit an initializer for its first enum element.
node_modules/tns-core-modules/module.d.ts(69,5): error TS2300: Duplicate identifier 'markup'.
node_modules/tns-core-modules/module.d.ts(70,5): error TS2300: Duplicate identifier 'script'.
node_modules/tns-core-modules/module.d.ts(71,5): error TS2300: Duplicate identifier 'style'.
node_modules/tns-core-modules/tns-core-modules.d.ts(4,1): error TS6200: Definitions of the following identifiers conflict with those in another file: "audio", "beacon", "cspreport", "download", "embed", "eventsource", "favicon", "fetch", "font", "form", "frame", "hyperlink", "iframe", "image", "imageset", "import", "internal", "location", "manifest", "object", "ping", "plugin", "prefetch", "script", "serviceworker", "sharedworker", "subresource", "style", "track", "video", "worker", "xmlhttprequest", "xslt", HeaderInit, WeakRef

Frameworks from tns-core-modules (e.g. TNSWidgets.framework) are referenced from both the consumer project and the library.

Xcode build...
error: unexpected duplicate task: CodeSign /Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework (in target 'sample')
error: unexpected duplicate task: CodeSign /Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework (in target 'sample')
error: Multiple commands produce '/Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework':
1) Target 'sample' has copy command from '/Users/jamie/Documents/git/react-nativescript/sample/node_modules/react-nativescript/node_modules/tns-core-modules-widgets/platforms/ios/TNSWidgets.framework' to '/Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework'
2) Target 'sample' has copy command from '/Users/jamie/Documents/git/react-nativescript/sample/node_modules/tns-core-modules-widgets/platforms/ios/TNSWidgets.framework' to '/Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework'
error: Multiple commands produce '/Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework/TNSWidgets':
1) Target 'sample' has copy command from '/Users/jamie/Documents/git/react-nativescript/sample/node_modules/react-nativescript/node_modules/tns-core-modules-widgets/platforms/ios/TNSWidgets.framework' to '/Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework'
2) Target 'sample' has copy command from '/Users/jamie/Documents/git/react-nativescript/sample/node_modules/tns-core-modules-widgets/platforms/ios/TNSWidgets.framework' to '/Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework'
warning: duplicate output file '/Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework' on task: PBXCp /Users/jamie/Documents/git/react-nativescript/sample/node_modules/tns-core-modules-widgets/platforms/ios/TNSWidgets.framework /Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework (in target 'sample')
warning: duplicate output file '/Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework/TNSWidgets' on task: PBXCp /Users/jamie/Documents/git/react-nativescript/sample/node_modules/tns-core-modules-widgets/platforms/ios/TNSWidgets.framework /Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework (in target 'sample')
warning: duplicate output file '' on task: PBXCp /Users/jamie/Documents/git/react-nativescript/sample/node_modules/tns-core-modules-widgets/platforms/ios/TNSWidgets.framework /Users/jamie/Documents/git/react-nativescript/sample/platforms/ios/build/Debug-iphonesimulator/sample.app/Frameworks/TNSWidgets.framework (in target 'sample')
note: Using new build systemnote: Planning buildnote: Constructing build description
** BUILD FAILED **

Unable to apply changes on device: A77F52A9-0201-47A7-8523-1F7C0CFBD57C. Error is: Command xcodebuild failed with exit code 65.

To Reproduce

  1. Create a library that depends on tns-core-modules
  2. Create an app that installs that library, and also depends upon (the same) version of tns-core-modules

Expected behavior

App is supposed to build correctly.

Sample project

https://github.com/shirakaba/react-nativescript

Additional context

npm dedupe gets things working, but does also remove all the duplicate dependencies in your library folder, preventing you from developing your library.

npm ls
# Lots of unrelated packages
โ”œโ”€โ”ฌ [email protected] -> /Users/jamie/Documents/git/react-nativescript/react-nativescript
โ”‚ โ”œโ”€โ”€ @types/[email protected] extraneous
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected] deduped
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected] deduped
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚ โ”‚   โ”œโ”€โ”€ [email protected] deduped
โ”‚ โ”‚   โ””โ”€โ”€ [email protected] deduped
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected] deduped
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected] deduped
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected] deduped
โ”‚ โ”‚ โ””โ”€โ”€ [email protected] deduped
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”€ [email protected] extraneous
โ””โ”€โ”ฌ [email protected]
  โ”œโ”€โ”€ [email protected]
  โ””โ”€โ”€ [email protected]

Note how tns-core-modules-widgets appears twice.

Related issues

question

All 4 comments

@shirakaba in the plugin source remove the tns-core-modules from the dependency list. You could install the tns-core-modules as a devDepedency (e.g. as done here) and that won't prevent you from accessing the tns-core-modules in your plugin code (e.g. as done here) as each NativeScript project would have the tns-core-modules installed in the end (e.g. your demo called sample is installing tns-core-modules as dependency).

Fantastic, that works!

I've applied your suggested fix in commit 92682e3 of my repo.

@shirakaba glad to hear you are able to move forward! As a side note I've read your roadmap and noticed that you need TSX support so perhaps you could refer to this plugin for inspiration.

@NickIliev That's invaluable, thank you! I'll add that as a note in the repo.

Before I can get as far as TSX, I'll first need to figure out how to bootstrap the app. I'll file ~this issue that I'm blocked on under the NativeScript main repository in a moment~; would be glad of any help with that, as well!

EDIT: it's more of a question than a bug, so I've submitted it to StackOverflow instead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NickIliev picture NickIliev  ยท  3Comments

erjdriver picture erjdriver  ยท  3Comments

ZMW9 picture ZMW9  ยท  3Comments

Anilinfo2015 picture Anilinfo2015  ยท  3Comments

trodellez picture trodellez  ยท  3Comments