Issue
I receive an error when I try to run tensorflow.js with jest. I import the node backend and it immediately errors. If I run normally (not using jest) then I get no such error.
FAIL src/policy.test.js
● Test suite failed to run
ReferenceError: TextEncoder is not defined
> 1 | import * as tf from '@tensorflow/tfjs-node';
| ^
2 | import {slide} from './util.js';
3 | import * as R from 'ramda';
4 |
at new PlatformBrowser (node_modules/@tensorflow/tfjs-core/src/platforms/platform_browser.ts:26:28)
at Object.<anonymous> (node_modules/@tensorflow/tfjs-core/src/platforms/platform_browser.ts:42:30)
at Object.<anonymous> (node_modules/@tensorflow/tfjs-core/src/index.ts:29:1)
at Object.<anonymous> (node_modules/@tensorflow/tfjs/src/index.ts:18:1)
at Object.<anonymous> (node_modules/@tensorflow/tfjs-node/dist/index.js:33:10)
at Object.<anonymous> (src/policy.js:1:1)
at Object.<anonymous> (src/policy.test.js:1:1)
I am wondering why this issue occurs and if I can work around it. If jest uses node internally for testing (right?) then the tensorflow node backend should work when imported.
Solution
I added this to my package.json
"jest": {
"testEnvironment": "node"
}
Apparently jest runs in a browser-like environment by default
Answered By - Thomas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.