Adornis/typescript

Support "module":"ESNext" (tsconfig)

Closed this issue · 1 comments

My project currently uses module:commonjs because that is what I got working

To enable dynamic import and real es modules, you need to set module to ESNext just like the official meteor typescript package does.

When I tried that, however, the emitted code was non-executable.

Looking in the packaged debug build code in .meteor/build/web.browser/app/app.js, I found raw un-transformed statements like

export const loadDynamicLib = async () => {
...
}

which gave the runtime error SyntaxError: Unexpected token export.

This is the tsconfig file I used - more or less a copy of the one created by meteor create --typescript

{
  "compilerOptions": {
    "target": "es2018",
    "module": "esNext",
    "lib": ["esnext", "dom"],
    "allowJs": true,
    "checkJs": false,
    "jsx": "preserve",
    "incremental": true,
    "noEmit": true,

    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "types": ["node", "mocha"],
    "esModuleInterop": true,
    "preserveSymlinks": true
  }
}

Using the meteor-provided typescript package the code instead compiled to (app.js):

module.export({
  loadDynamicLib: () => loadDynamicLib,
  checkPasswordStrengthAsync: () => checkPasswordStrengthAsync
});

const loadDynamicLib = async () => {
...
};

So I wonder what magic needs to be done to get this typescript compiler to generate the same javascript as the meteor typescript package?
Is this some babel thing?

The web.browser.legacy version of app.js indicates that, since it has:

module.link("@babel/runtime/regenerator", {
  default: function (v) {
    _regeneratorRuntime = v;
  }
}, 0);
module.export({
  loadDynamicLib: function () {
    return loadDynamicLib;
  }
});

var loadDynamicLib = function () {
...

Housecleaning. This compiler is deprecated