0

I am currently developing in Next.js and React (TypeScript).

Then a problem arose.

It is the inability to load js files.

I have tried the following.
 ・Import javascript modules
  import * as module from '../../../script';
 ・require code
  const remise = require('../../../script/rtoken-3.0.0');   
Neither did it work.

Please tell me how to write it. Thank You.

Here is the code. ・js(path:../../../script/rtoken-3.0.0.min.js)

(function (window, undefined) {
  var CONNECTION_TIMEOUT = 5000;

  function rtoken() {
    this.consumerID = '';
    this.SessionTimeout = 60000;
    this.ConnectionAddress = '';
    ~
    var rtoken = this;
    window.onbeforeunload = function () {
      rtoken.Abort();
    };
    window.onpagehide = function () {
      rtoken.Abort();
    };
  }
  rtoken.prototype = {
    Init: function () {
      this.consumerID = getUUID();
      this.SessionTimeout = 60000;
      this.TokenType = '';
   ~
    },
    Create: function () {
      var self = this;
      requestData = "{\"SessionID\":\"" + this.consumerID + "\"," + "\"TokenType\":\"" + this.TokenType + "\"," + "\"Sequence\":\"" + this.Sequence + "\"," + "\"Options\":\"" + this.Options + "\"}";
      exJsonp(self.ConnectionAddress, CONNECTION_TIMEOUT, requestData, "CreateToken", function (data) {
       ~
      });
    },
  };

  function exJsonp(url, htttimeout, RequestData, MethodName, Callback) {
    try {
      $.ajax({
        url: url,
        type: 'POST',
        dataType: 'jsonp',
        data: encodeURIComponent(RequestData),
        jsonpCallback: MethodName,
        timeout: htttimeout,
        success: function (data) {
          Callback(data);
        },
        error: function (data) {
          Callback(data);
        },
        complete: function (data) {}
      });
    } catch (e) {
      Callback(null);
    }
  };

  function getUUID() {
    var uuid, i, random;
    uuid = "";
    for (i = 0; i < 32; i++) {
      ~
    }
    return uuid;
  };
  if (!window.remise) {
    window.remise = {};
  }
  window.remise.rtoken = rtoken;
})(window);

tsfile()

~
import * as rtoken from '../../../script/rtoken-3.0.0.min'; // ×

export const Index = (props) => {
  const jsModule = require('../../../script/rtoken-3.0.0');
 var token= jsModule();
  // What does not come in to token
  console.log('token:', token);

  return (
    null
  )
}
3

1 Answer 1

0

Make sure you allow turn on allowJs option in tsconfig.json. And after you import depending on your configuration, you can ignore the linting errors

Sign up to request clarification or add additional context in comments.

4 Comments

yes. I already have allowjs in tsconfig.json...
so no errors but token is undefined?
It seems that jQuery and React are not compatible.
you can use them both together. but it is not practical as React interacts with VDOM and JQuery interacts with actual DOM. so you would see red flags everywhere unless you find a good way to control them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.