Nativescript-cli: Cannot run emulator with tns as devDependency

Created on 16 Feb 2016  路  13Comments  路  Source: NativeScript/nativescript-cli

I'm trying to setup the dev environment for other developers so that they don't have to install modules globally. I am able to install nativescript as a dev dependency and use npm scripts to use the local binary. Building the ios app works fine. I'm not able to run the emulator unfortunately. Here's an output of the logs

** BUILD SUCCEEDED **

Revert typescript version to beta
Project successfully built
Using  /Users/Jeremiah/Projects/worklife/mobile-app/AppName/platforms/ios/build/emulator/AppName.app
Starting iOS Simulator
Feb 16 14:16:22 Jeremiahs-MacBook-Pro AppName[72734]: 1   0x73d76 -[TNSRuntime executeModule:]

Feb 16 14:16:22 Jeremiahs-MacBook-Pro AppNAme[72734]: 2   0x3541e main
Feb 16 14:16:22 Jeremiahs-MacBook-Pro AppNAme[72734]: 3   0x39dea21 start
Feb 16 14:16:22 Jeremiahs-MacBook-Pro AppName[72734]: 4   0x1
Feb 16 14:16:22 Jeremiahs-MacBook-Pro AppName[72734]: undefined: JS ERROR Error: Failed to find module 'stream' relative to 'file:///app/tns_modules/xml/lib/xml.js'. Computed path: 'app/tns_modules/stream.js'.
Feb 16 14:16:22 Jeremiahs-MacBook-Pro com.apple.CoreSimulator.SimDevice.7EC1FE7F-61C4-494C-ABDD-7E6D32BCE45A.launchd_sim[71860] (UIKitApplication:com.progress.ios.AppName[0x60b5][72734]): Service exited due to signal: Segmentation fault: 11
bug

All 13 comments

Building the app would work okay, because the error is occurring when you run the app. It can't find the module 'stream', so where you're requiring modules like so var * = require("*") there could be a typo, or that module hasn't be included in your project.

I can confirm this is an issue and not related to the requiring of modules in user code. If i install latest CLI as dev dependency and try to deploy the app to simulator (i've tested with VS android simulator) it does not work. Then if you remove the dev dependency and deploy with the tns command installed globally it works ok.

Will there be some type of fix for this?

@harlanj, @PeterStaev can you please confirm that this issues is still valid and provide exact steps to reproduce.

Just tested with {N} 2.0.1 and following steps:

npm init (and populate the wizard)
npm install --save-dev nativescript
node_modules/.bin/tns create TestApp
node_modules/.bin/tns run ios --emulator --path TestApp

It works.

Actually I spoke too soon. Here is the scenario i'm testing:

  1. I have a sample app created with the global tns
  2. In the folder of the app I run npm install nativescript --save-dev
  3. In the folder of the app I run node_modules\.bin\tns deploy android. The build completes successful but when run on android the app throws the error:
    image
    I opened the package.json of the app and seems the install of nativescript also put the tns-core-modules in the devDependencies section (although it was already present in the dependencies section before starting with step 2). I manually removed them from there, deleted the platforms folder and did again step 3 above. Again build completes w/o problems but when deployed the following error pops up:
    image

Currently this is not supported scenario.

Do you have any plans when this will be a supported scenario?

I'm a bit wondering how we could do support of a {N} application for enterprise, where we have many versions, built/released with different {N} versions, because of the time span.

Let's say 3 years from now we released 6 versions, and each one of them has different {N} version. How we could support this easily, assuming that a dev machine has one single nativescript installation, always up to date?

I understand the scenario is hypothetical, but if {N} wants to see long-term apps, built to last years, this has to be addressed IMO?

I've got your point, may be for this purpose we can have something like Node version manager.
How we solve such problems (need to have multiple CLIs on same machine) now is local installations.

See my comment from Jun 7.

The problem @PeterStaev describe is when you install {N} inside folder of your app, it is not a problem to have local installations one folder above or somewhere else.

Thanks! I second that problem: {N} being installed as npm module within the app. It could give very nice ability to host all your app source code in one repository, do single git clone, run a prep script and then build and have the app running.

This will save the need for having long list of "How to install, configure and run {N}" for any new user to such a repository. It won't eliminate the need of such doc, but it'll be much shorter.

In addition to that, it'll also eliminate the need to have multiple global {N} CLIs.

Now you can do almost the same (have a CLI as dev dependency), just a bit different structure:

root
|--nativescript (dev dependency of root project, not dev dependency of your app)
|--app

Agree that it will be nice if we also work with the case when structure is like this:

root
|--app
    |--node_modules
        |--nativescript

But we can't promise it will be in next release.

What we (with @donangel ) are trying to achieve is to use npm as build tool. For example:

package.json

{
    "nativescript": {
        "id": "com.foo.app",
        "tns-ios": {
            "version": "2.1.1"
        },
        "tns-android": {
            "version": "1.7.1"
        }
    },
    "dependencies": {
        "tns-core-modules": "^1.6.0"
    },
    "devDependencies": {
        "nativescript": "^1.6.0"
    },
    "scripts": {
        "postinstall": "tns platform add ios && tns platform add android",
        "emulate:ios": "tns emulate ios",
        "emulate:android": "tns emulate android",
        "start:ios": "tns run ios",
        "start:android": "tns run android"
    }
}

then

$ git clone foo
$ cd foo
$ npm install
$ npm start emulate:ios

It will be nice to avoid these questions as well:

? Do you want to visit the official documentation? No
? Do you want to run the setup script? No

@palavrov you see those massages only if tns doctor detect issues with your system.
Somewhere above those lines you should see info what is wrong.

Doctor is executed ans post install script when you install CLI, you can skip it (this will reduce install time with at least 30 seconds) if you install CLI with

npm install nativescript --ignore-script

Re original problem - we are aware and we will try to fix it in some of the releases after {N} 2.2.

@PeterStaev @donangel @palavrov It looks issue is fixed in {N} 3.0.0.

Testing with this steps:

tns create TestApp (global tns)
cd TestApp
npm install nativescript --save-dev
node_modules/.bin/tns run android -> looks OK
node_modules/.bin/tns run ios -> looks OK

Feel free to reopen if you still encounter some issues.

Was this page helpful?
0 / 5 - 0 ratings