iost.js icon indicating copy to clipboard operation
iost.js copied to clipboard

test.js:20 Uncaught (in promise) ReferenceError: IOST is not defined

Open garry191091 opened this issue 5 years ago • 10 comments

How can I resolve this issue?

test.js:20 Uncaught (in promise) ReferenceError: IOST is not defined

garry191091 avatar Nov 01 '19 07:11 garry191091

You should import IOST library like below:

const IOST = require('iost')

or

import IOST from 'iost'

nujabes403 avatar Nov 01 '19 07:11 nujabes403

I have added the import IOST from 'iost'. it displays the error test.js:1 Uncaught SyntaxError: Cannot use import statement outside a module.

garry191091 avatar Nov 01 '19 08:11 garry191091

@garry191091 Could you share your code?

nujabes403 avatar Nov 01 '19 08:11 nujabes403

`import IOST from iost ; (function() {

var transfer;

document.addEventListener("DOMContentLoaded", async function(event) {
  await new Promise(done => setTimeout(() => done(), 500));

  IWalletJS.enable().then(function(account) {
    if(!account) return;

	const iost = IWalletJS.newIOST(IOST);

    transfer = function() {
		
      const tx = iost.callABI("token.iost", "transfer", ["iost", account, '2JPTB3X9ePHuKcWKZFCENUtsR4TRqnD1bBq6a45e4cAXhQodMAcqJghbrYUKgktUErUE434vZVrXiu9oMhJrKdnq', "10", "dapp test memo"]);
      tx.addApprove("iost", "10");

      console.log(tx.getApproveList());
      iost.signAndSend(tx)
        .on('pending', function(txid) {
          log("txid: " + txid);
			
		})
        .on('success', function(result) {
          log("res: " + JSON.stringify(result));
		
        })
        .on('failed', function(failed) {
          log("failed: " + JSON.stringify(failed));
		  	
		})
    }
  })
})

})();

`

garry191091 avatar Nov 01 '19 09:11 garry191091

How about using const IOST = require('iost') instead?

nujabes403 avatar Nov 01 '19 09:11 nujabes403

Yes, I have added this but this is the new error now. Uncaught Error: Module name "iost" has not been loaded yet for context: _. Use require([])

Also, previously in my above code. It checks iost enables if it is unlocked or locked. IWalletJS.enable().then(function(account) but it is giving the error of Uncaught (in promise) ReferenceError: IOST is not defined .

What can be missing?

garry191091 avatar Nov 02 '19 04:11 garry191091

here is the error.

https://ibb.co/k54VGFr

garry191091 avatar Nov 02 '19 05:11 garry191091

Could you share the code importing test.js?

nujabes403 avatar Nov 02 '19 07:11 nujabes403

` function transfer(){

	alert('no') ;
 
	IWalletJS.enable().then(function(account) {
	
	if(!account) return;  
		
		const IOST = require('iost')	;
		
		
		
		alert('yes') ;
	})
	
}

`

garry191091 avatar Nov 02 '19 07:11 garry191091

On adding const IOST = require('iost') I get this error Uncaught (in promise) Error: Module name "iost" has not been loaded yet for context: _. Use require([])

garry191091 avatar Nov 02 '19 07:11 garry191091