question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when dynamically importing tf.js from browser console

See original GitHub issue

To 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:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
bileschicommented, Jul 25, 2018

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?

var script = document.createElement("script");
script.type = 'text/javascript';
script.src = 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest';
document.head.appendChild(script);
0reactions
bileschicommented, Aug 2, 2021

I just tried this in chrome and it appeared to work. Can you offer a more complete bug report? Thanks.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found