0

I'm trying to bundle a NativeScript App with the snapshot flag like this:

tns build android --bundle --env.snapshot 

The following error appears:

ERROR in NativeScriptSnapshot. Snapshot generation failed!
Target architecture: x86
# Script run failed in <embedded>@736:2461
ReferenceError: com is not defined


#
# Fatal error in ../src/snapshot/mksnapshot.cc, line 175
# Check failed: blob.data.
#

Anyone have an idea how to fix that?

kenny
  • 1,628
  • 20
  • 14

2 Answers2

0

The problem was that the app.scss in the root folder had been renamed to something else. Make sure it it will pass the regex ( default: /^\.\/app\.(css|scss|less|sass)$/ ) in the vendor.ts file.

kenny
  • 1,628
  • 20
  • 14
0

See How it works part

Modules included in the snapshotted bundle can still contain native API calls given that they are not evaluated immediately upon module loading. For example, the following module:

require("application");

var time = new android.text.format.Time(); can’t be snapshotted because it touches android.text.format.Time API which is not available. However, in this one:

require("application");

function getTime() { return new android.text.format.Time(); } the native API access is not evaluated on module execution. Given that getTime() is called later in the fully featured V8 context provided by the Android runtime, we are safe to include the module in the snapshotted bundle.

If the snapshotting step fails because of a reference to an undefined API, try some of the following solutions:

If you can change the module containing the forbidden API call, wrap the guilty code in a function that is called once the app is running on device Keep the module in the bundle but make sure all require calls of the non-snapshotable module are executed once the app is running on device: require("application"); var m = require("non-snapshotable-module");

function doSomething() { return m.someMethod(); } The code above has a higher chance to be successfully snapshotted if it loads the non-snapshotable module when it actually needs it:

require("application");

function doSomething() { return require("non-snapshotable-module").someMethod(); } If doSomething() function is never called in snapshot context, the non-snapshotable module will not be evaluated and blob generation will succeed.

Exclude the module containing the forbidden API call from the snapshotted bundle.

So make sure you are not referencing com in snapshot time.

Radouane ROUFID
  • 10,595
  • 9
  • 42
  • 80