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
  )
}
tatsuya
  • 7
  • 4
  • Does this answer your question? [Mixing JavaScript and TypeScript in Node.js](https://stackoverflow.com/questions/49640121/mixing-javascript-and-typescript-in-node-js) – Stav Noy Sep 01 '23 at 08:01
  • @StavNoy Thank you. But no resolution was reached.... – tatsuya Sep 01 '23 at 08:24

1 Answers1

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