Error when dynamically importing tf.js from browser console
See original GitHub issueTo get help from the community, check out our Google group.
TensorFlow.js version
0.12.0
Browser version
Chrome Version 67.0.3396.99 (Official Build) (64-bit) macOS
Describe the problem or feature request
When I tried to import tf.js using the import() function that chrome provides in the chrome console, an error occurred saying:
tfjs@0.12.0:2 Uncaught (in promise) TypeError: Cannot read property 'tf' of undefined
at tfjs@0.12.0:2
at tfjs@0.12.0:2
I then checked the tf.js source and see at the loading stage it has:
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.tf = global.tf || {})));
}(this, (function (exports) { 'use strict';
...
// actual tf.js implementation
...
So apparently in a promise-based dynamic loading this
is undefined
instead of the window
object. Simply change this
to window
on the last line will do the trick, but I guess that’ll break in some other scenarios.
Code to reproduce the bug / link to feature request
Simply run import('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.12.0').then((tf) => {})
in your chrome console.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Unable to dynamically import TensorFlow.js - Stack Overflow
I am trying to dynamically import TensorFlow. js using the import function. However, I always receive a TypeError: t is undefined error. The ......
Read more >Dynamic Import - For Beginner - YouTube
Static imports is the standard way to import a file at the top of your js module using standard import syntax. import {...
Read more >What are Dynamic Imports and how to use them? - Initialyze
Dynamic imports or Code Splitting is the practice of breaking up your JavaScript modules into smaller bundles and loading them dynamically ...
Read more >Platform and environment | TensorFlow.js
TensorFlow.js works in the browser and Node.js, and in both platforms there ... import {setWasmPath} from '@tensorflow/tfjs-backend-wasm';
Read more >Fix list for IBM WebSphere Application Server V8.5
PH26192, Web server crashes when WebSphere plugin dynamically reloaded ... General, PH04234, /ibm/console/ChartCollection.do javascript injection XSS ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve not had success using the
import
command from directly in the JS console.In the mean time, does the following workaround work for you?
I just tried this in chrome and it appeared to work. Can you offer a more complete bug report? Thanks.