Nativescript-cli: Error: spawn E2BIG

Created on 22 Feb 2017  ยท  10Comments  ยท  Source: NativeScript/nativescript-cli

Preparing project...
[31;1mProcessing node_modules failed. Error: spawn E2BIG
[NSDebugAdapter] The tns command finished its execution with code 127.
getconf ARG_MAX
2097152
All NativeScript components versions information
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Component        โ”‚ Current version โ”‚ Latest version โ”‚ Information      โ”‚
โ”‚ nativescript     โ”‚ 2.5.0           โ”‚ 2.5.1          โ”‚ Update available โ”‚
โ”‚ tns-core-modules โ”‚ 2.5.1           โ”‚ 2.5.1          โ”‚ Up to date       โ”‚
โ”‚ tns-android      โ”‚ 2.5.0           โ”‚ 2.5.0          โ”‚ Up to date       โ”‚
โ”‚ tns-ios          โ”‚ 2.3.0           โ”‚ 2.5.0          โ”‚ Update available โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Running on Ubuntu 16.10, while I did not have such problems with NS 2.0.0

bug

Most helpful comment

You can't have nativescript as a dependency, if you're going to install it locally, install it as a devDependency or even better use it globally.

to fix your issue:

  • npm uninstall nativescript --save
  • npm install -g nativescript
  • tns build android

All 10 comments

I experienced the same issue. The result of tns prepare android --log trace > build.log can be seen at the attachment.
I tried to identify the bug.
It may be at traverseDependency (source nativescript-cli/lib/tools/node-modules/node-modules-dependencies-builder.ts), because {"name":"d","directory":"/home/myproject/node_modules/d","depth":0} shows up many times in the log.

prepare.log.txt

I solved my issue by removing the number-generator package, because it has an incorrect dependency environment for eslint causing a cyclic import for es6-iterator. To permit use this package I changed it's eslint to devDependencies of package.
Also i believe this routine should be fixed to prevent similar issues. tx.

@rLoka, @silveirado can you provide steps to reproduce and the version of cli you're using?

@Plamen5kov I updated from 2.0.0 to 2.5.0 and that is what happened. I am on Ubuntu 16.10.
Here is the project source https://github.com/Non-BinaryT/OfficeEquipmentTracker .. you can try building it yourself.

Thank you @rLoka, I managed to reproduce the problem and will investigate.

You can't have nativescript as a dependency, if you're going to install it locally, install it as a devDependency or even better use it globally.

to fix your issue:

  • npm uninstall nativescript --save
  • npm install -g nativescript
  • tns build android

Steps to reproduce this issue:

$ tns create issue-2561 --ng
$ cd issue-2561
$ npm i -S lodash
$ npm i -S moment
$ npm i -S nativescript-cardview
$ npm i -S nativescript-sqlite
$ npm i -S nativescript-statusbar
$ npm i -S nativescript-websockets
$ npm i -S number-generator
$ tns platform add android
$ tns prepare android
$ echo "Everything ok"
$ npm i -S eslint eslint-plugin-compat
$ tns update
$ tns prepare android

Result:

Executing before-prepare hook from /home/derotino/desenvolvimento/issue-2561/hooks/before-prepare/nativescript-dev-android-snapshot.js
Executing before-prepare hook from /home/derotino/desenvolvimento/issue-2561/hooks/before-prepare/nativescript-dev-typescript.js
Found peer TypeScript 2.1.6
Preparing project...
Processing node_modules failed. Error: spawn E2BIG

I know that the eslint eslint-plugin-compat packages must be in devDependecies, it has been fixed at PR [#3] (https://github.com/MartinHelmut/number-generator/pull/3) from 'number generator' package. But indeed miss happens may occur.

@silveirado thank you, for the detailed steps to reproduce. It's a node restriction on the size of arguments you can call it with, we'll fix it as soon as possible.
Until we do, all we can provide as a workaround is to install any non-production dependencies as devDependencies.

As mentioned above - the problem arises from passing arguments of length greater, than that allowed by the OS, when spawning a new process. This is, as seen from the provided logs, a result of traversing cyclic production dependencies. The prepare step during build also slows up dramatically.

The script that is ran in node is responsible for checking whether any of the installed application plugins has declared dependency on the public v8 API, so that we may determine whether to distribute optimized (lower package size), or the regular runtime package.

We can currently address the E2BIG/ENAMETOOLONG (Win) problem by defaulting to using the optimized version of the runtime if an error is thrown while spawning the child process. This will allow the CLI process to continue, and the application will likely start up. What concerns me most is that these cyclic dependencies may be used in release builds, and may cause problems runtime/increase app size. So the responsibility for clean and neat dependencies should still fall in the developer's hands.

If and when the changes https://github.com/NativeScript/nativescript-cli/blob/5a3266a70b8e1a1fbb39380eee8ea63cadf0b48f/lib/tools/node-modules/node-modules-builder.ts#L135 in #2532 make it in master, the node script can instead read the production dependencies from a file, which should eliminate this problem entirely.

Merged PR #2604 so that the prepare process no longer terminates if passing too many arguments (a result of bad dependency tree) to a new node process. If the above error is caught then the runtime will fallback to the default optimized (stripped v8 symbols table) android runtime without checking whether any of the nativescript plugins depend on v8.

Was this page helpful?
0 / 5 - 0 ratings