Problem calling node.js app - scripts.node.runtime.ScriptExitedError - UInt8Array is not defined

Not applicable

Deploying my first node.js application in Apigee Edge. Everything deployed OK. Was able to successfully import all dependencies from package.json, however am getting the following error...

{
  "fault": {
    "faultstring": "Script node executed prematurely: ReferenceError: \"Uint8Array\" is not defined.\n    at /organization/environment/api/node_modules/tedious/node_modules/iconv-lite/lib/extend-node.js:10\n    at /organization/environment/api/node_modules/tedious/node_modules/iconv-lite/lib/index.js:139\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at /organization/environment/api/node_modules/tedious/lib/value-parser.js:11\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at /organization/environment/api/node_modules/tedious/lib/token/returnvalue-token-parser.js:15\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at /organization/environment/api/node_modules/tedious/lib/token/stream-parser.js:23\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at /organization/environment/api/node_modules/tedious/lib/token/token-stream-parser.js:19\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at /organization/environment/api/node_modules/tedious/lib/connection.js:63\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at /organization/environment/api/node_modules/tedious/lib/tedious.js:13\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at /organization/environment/api/node_modules/tedious-connection-pool/lib/connection-pool.js:2\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at /organization/environment/api/apm-api-server.js:6\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:497\n    at startup (trireme.js:142)\n    at trireme.js:923\n",
    "detail": {
      "errorcode": "scripts.node.runtime.ScriptExitedError"
    }
  }
}

Followed instructions here... https://community.apigee.com/articles/1531/how-to-import-a-nodejs-module-to-apigee-edge.html and all went well until calling service.

I successfully installed npm dependencies from package.json with...

curl -X POST -H "Authorization: Basic XXXXXXX" "Content-Type: application/x-www-form-urlencoded" -d 'command=install' 'http://<myserver>/v1/organizations/<myorg>/apis/sample-nodejs/revisions/1/npm'

And checked with...

curl -X GET -H "Authorization: Basic XXXXXXX" 'http://<myserver>/v1/organizations/<myorg>/apis/sample-nodejs/revisions/1/npm'

...and can see all the dependencies resolved.

Redeployed OK.

The same node.js app is working standalone from command line with...

> node myNodeApp.js

Any help would be much appreciated.

Thanks,

Martyn.

Solved Solved
1 6 1,661
1 ACCEPTED SOLUTION

Yes, You're not doing anything wrong. You are running into a limitation with the nodejs support in Apigee Edge.

In older versions of Apigee Edge, there was no support for running nodejs apps that use native arrays (like Uint8Array, Int16Array , Float32Array, and so on), or that use modules that depend on native arrays.

Let's step back and cover some background: the nodejs support in Apigee Edge is delivered via an open-source project called trireme. In v0.8.6 of trireme, there was an upgrade to Rhino 1.7.7. According to the release notes for trireme, this change introduces support for native arrays, aka JavaScript typed arrays, among many other things.

For Apigee-managed versions of Edge (Edge in the public cloud), Apigee has updated trireme to the newer versions (at least 0.8.7), so you won't run into this problem any longer. BUT, people who run Apigee Edge themselves (customer-managed Edge) may have an older version of Edge that has an older (pre-v0.8.6) version of trireme. These older versions of trireme will throw the error that you are seeing. The use of Uint8Array is becoming more common in node modules, and the error won't be specific to any one particular module.

If YOU DO have OPDK, how can you avoid the problem?

There's no special incantation you can utter at the time of proxy import to make it work. To avoid the problem, you need to update trireme in your Edge.

The official way to get updated trireme modules in customer-managed Apigee Edge, aka OPDK, is via blessed patches from Apigee. For testing purposes, you can quickly self-patch OPDK, replacing the old versions of the trireme jars in /opt/apigee4/edge-gateway/lib/thirdparty , or whatever is the appropriate directory on your version of OPDK, with the newer trireme jars.

As of trireme v0.8.9, these jars are:

trireme-core-0.8.9.jar
trireme-crypto-0.8.9.jar
trireme-kernel-0.8.9.jar
trireme-node10src-0.8.9.jar
trireme-util-0.8.9.jar

After doing so, you will need to restart the Message Processors.

Of course this do-it-yourself approach is not appropriate for a production system. For that I suggest you inquire with Apigee Support, to ask for an official patch to your version of OPDK to get updated trireme support.

HTH

View solution in original post

6 REPLIES 6

Not applicable

Hi @Martyn Hill , based on the error above, I guess that you're trying to use TypeArray NPM module. Running NPM on the server should do the trick. However, for some reason, it's not being picked up by the engine. So, to troubleshoot it further, I'd suggest running these steps:

1. Ensure that package.json contains the dependency to TypeArray module. If it's not listed as a "typedarray" dependency, please include it and try the steps to install NPM dependencies you followed above.

2. If the problem persists, try apigeetool with -U flag. -U flag uploads the modules, so there's no need to run NPM on the server. If this method works, it means that apigeetool and the NPM management API are not achieving the same result, which could be considered a bug. This method so far has worked consistently for me, please give it a try it and let us know your results.

Hope it helps!

@Diego Zuluaga OK thank you! I will give that a try and report back.

@ravi_tanniru getting similar error

{"fault":{"faultstring":"Script node executed prematurely: ReferenceError: \"Uint8Array\" is not defined.\n at \/organization\/environment\/api\/node_modules\/body-parser\/node_modules\/raw-body\/node_modules\/iconv-lite\/lib\/extend-node.js:10\n at \/organization\/environment\/api\/node_modules\/body-parser\/node_modules\/raw-body\/node_modules\/iconv-lite\/lib\/index.js:139\n at module.js:456\n at module.js:474\n at module.js:356\n at module.js:312\n at module.js:364\n at require (module.js:380)\n at \/organization\/environment\/api\/node_modules\/body-parser\/node_modules\/raw-body\/index.js:16\n at module.js:456\n at module.js:474\n at module.js:356\n at module.js:312\n at module.js:364\n at require (module.js:380)\n at \/organization\/environment\/api\/node_modules\/body-parser\/lib\/read.js:15\n at module.js:456\n at module.js:474\n at module.js:356\n at module.js:312\n at module.js

Yes, You're not doing anything wrong. You are running into a limitation with the nodejs support in Apigee Edge.

In older versions of Apigee Edge, there was no support for running nodejs apps that use native arrays (like Uint8Array, Int16Array , Float32Array, and so on), or that use modules that depend on native arrays.

Let's step back and cover some background: the nodejs support in Apigee Edge is delivered via an open-source project called trireme. In v0.8.6 of trireme, there was an upgrade to Rhino 1.7.7. According to the release notes for trireme, this change introduces support for native arrays, aka JavaScript typed arrays, among many other things.

For Apigee-managed versions of Edge (Edge in the public cloud), Apigee has updated trireme to the newer versions (at least 0.8.7), so you won't run into this problem any longer. BUT, people who run Apigee Edge themselves (customer-managed Edge) may have an older version of Edge that has an older (pre-v0.8.6) version of trireme. These older versions of trireme will throw the error that you are seeing. The use of Uint8Array is becoming more common in node modules, and the error won't be specific to any one particular module.

If YOU DO have OPDK, how can you avoid the problem?

There's no special incantation you can utter at the time of proxy import to make it work. To avoid the problem, you need to update trireme in your Edge.

The official way to get updated trireme modules in customer-managed Apigee Edge, aka OPDK, is via blessed patches from Apigee. For testing purposes, you can quickly self-patch OPDK, replacing the old versions of the trireme jars in /opt/apigee4/edge-gateway/lib/thirdparty , or whatever is the appropriate directory on your version of OPDK, with the newer trireme jars.

As of trireme v0.8.9, these jars are:

trireme-core-0.8.9.jar
trireme-crypto-0.8.9.jar
trireme-kernel-0.8.9.jar
trireme-node10src-0.8.9.jar
trireme-util-0.8.9.jar

After doing so, you will need to restart the Message Processors.

Of course this do-it-yourself approach is not appropriate for a production system. For that I suggest you inquire with Apigee Support, to ask for an official patch to your version of OPDK to get updated trireme support.

HTH

Do you know when did Edge in public cloud updated trireme to the newer version? We ran into a similar problem a few months ago.

I believe January 2016. Certainly by March 2016.