How to import library-generated IIEF style JavaScript file?

255 Views Asked by At

Is there any way to import some library-generated code which does not have export vars? Which module options should be set in tsconfig.json file?

Documents

Environment

Example

js-routes generate a code like below based on routes.rb:

/*
File generated by js-routes 1.3.3
Based on Rails routes of MyApplication
 */

(function() {
    ...
    return root.Routes;
  };

  if (typeof define === "function" && define.amd) {
    define([], function() {
      return createGlobalJsRoutesObject();
    });
  } else {
    createGlobalJsRoutesObject();
  }

}).call(this);

If you import in 'module=es2015' style,

import { Routes } from '../path/to//generated/js_routes';

tsc warns:

[ts] File '/path/to/client/generated/js_routes.js' is not a module.
1

There are 1 best solutions below

0
On

You can try to require the file, and see what's the output of that:

import Routes = require('../path/to//generated/js_routes');