From cd8775f51891a6ef1a880d1f9bc76c961e6b10e1 Mon Sep 17 00:00:00 2001 From: Jon Campbell Date: Tue, 4 Feb 2025 19:50:29 -0800 Subject: [PATCH] Fix Node JS Samples (#23581) ### Description The Node JS Samples included in the repository have outdated package references that are broken, which are fixed in this PR. ### Motivation and Context The samples included in this repository should just work, but sadly do not. The reason is that they are using very outdated references for the npm modules. This fix updates the dependencies to the current onnxruntime-node, which fixes the samples. Also adds a small update to the .gitignore to exclude the node_modules directories in the samples directory, which keeps the local repo changelist cleaner. --- samples/nodejs/.gitignore | 3 ++- samples/nodejs/01_basic-usage/index.js | 2 +- samples/nodejs/01_basic-usage/package.json | 2 +- samples/nodejs/02_create-tensor/index.js | 2 +- samples/nodejs/02_create-tensor/package.json | 2 +- samples/nodejs/04_create-inference-session/index.js | 2 +- samples/nodejs/04_create-inference-session/package.json | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/samples/nodejs/.gitignore b/samples/nodejs/.gitignore index 16fbf90a90..92058f1cf8 100644 --- a/samples/nodejs/.gitignore +++ b/samples/nodejs/.gitignore @@ -1,2 +1,3 @@ !**/*.onnx -package-lock.json \ No newline at end of file +package-lock.json +node_modules diff --git a/samples/nodejs/01_basic-usage/index.js b/samples/nodejs/01_basic-usage/index.js index 886b7a9909..befede80f9 100644 --- a/samples/nodejs/01_basic-usage/index.js +++ b/samples/nodejs/01_basic-usage/index.js @@ -1,5 +1,5 @@ 'use strict'; -const ort = require('onnxruntime'); +const ort = require('onnxruntime-node'); // use an async context to call onnxruntime functions. async function main() { diff --git a/samples/nodejs/01_basic-usage/package.json b/samples/nodejs/01_basic-usage/package.json index 177ebaeda0..4c153a9d52 100644 --- a/samples/nodejs/01_basic-usage/package.json +++ b/samples/nodejs/01_basic-usage/package.json @@ -7,6 +7,6 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "onnxruntime": "0.0.1-dev.20200429.2" + "onnxruntime-node": "^1.20.1" } } diff --git a/samples/nodejs/02_create-tensor/index.js b/samples/nodejs/02_create-tensor/index.js index 8c14d63bd3..7aa7f0ffaa 100644 --- a/samples/nodejs/02_create-tensor/index.js +++ b/samples/nodejs/02_create-tensor/index.js @@ -1,5 +1,5 @@ 'use strict'; -const Tensor = require('onnxruntime').Tensor; +const Tensor = require('onnxruntime-node').Tensor; // // create a [2x3x4] float tensor diff --git a/samples/nodejs/02_create-tensor/package.json b/samples/nodejs/02_create-tensor/package.json index cc58b19854..4e18388759 100644 --- a/samples/nodejs/02_create-tensor/package.json +++ b/samples/nodejs/02_create-tensor/package.json @@ -7,6 +7,6 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "onnxruntime": "0.0.1-dev.20200429.2" + "onnxruntime-node": "^1.20.1" } } diff --git a/samples/nodejs/04_create-inference-session/index.js b/samples/nodejs/04_create-inference-session/index.js index 0435f435a6..a662c8083a 100644 --- a/samples/nodejs/04_create-inference-session/index.js +++ b/samples/nodejs/04_create-inference-session/index.js @@ -1,7 +1,7 @@ 'use strict'; const fs = require('fs'); const util = require('util'); -const InferenceSession = require('onnxruntime').InferenceSession; +const InferenceSession = require('onnxruntime-node').InferenceSession; // use an async context to call onnxruntime functions. async function main() { diff --git a/samples/nodejs/04_create-inference-session/package.json b/samples/nodejs/04_create-inference-session/package.json index a1af7d0756..75a8c525f9 100644 --- a/samples/nodejs/04_create-inference-session/package.json +++ b/samples/nodejs/04_create-inference-session/package.json @@ -7,6 +7,6 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { - "onnxruntime": "0.0.1-dev.20200429.2" + "onnxruntime-node": "^1.20.1" } }