Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importHelpers in tsconfig.json #106

Closed
kwonoj opened this issue Oct 28, 2017 · 4 comments
Closed

importHelpers in tsconfig.json #106

kwonoj opened this issue Oct 28, 2017 · 4 comments

Comments

@kwonoj
Copy link

kwonoj commented Oct 28, 2017

Issue description or question

If tsconfig.json have config around helper functions,

   "importHelpers": true,
    "noEmitHelpers": true,

it seems noEmitHelpers are honored but importHelpers are not, so some of downlevel transpiled helper is not being referenced. Not sure if this specific configuration related or default behavior.

Sample code

//import 'tslib' //if explicitly imports, below works
const a = () => Promise.resolve('a');
(async() => console.log(await a()))();

tsconfif

{
  "compilerOptions": {
    "removeComments": false,
    "preserveConstEnums": true,
    "sourceMap": true,
    "allowJs": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "suppressImplicitAnyIndexErrors": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "noImplicitThis": true,
    "noUnusedParameters": true,
    "importHelpers": true,
    "noEmitHelpers": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es2016",
    "jsx": "react",
    "outDir": ".tmp/build",
    "lib": [
      "es2016",
      "dom"
    ],
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "include": [
    "src/**/*",
    "build/**/*",
    "spec/**/*"
  ],
}

Sample repository link

If the issue can not be reproduced just using the quokka file above
(for example because it requires/imports some files from your project),
please create a small repository where the issue can be reproduced.

Quokka.js Console Output

​​__awaiter is not defined​​
  at ​​​__dirname​​​ ​quokka.ts:2:12​
  at ​quokka.ts:2:12​

Code editor version

[x] Visual Studio Code v1.?
Webstorm v?
Atom v1.?

OS name and version

[x] Windows
OSX
Linux

@ArtemGovorov
Copy link
Member

I didn't have a chance to fully investigate why it's happening, but the issue doesn't see to be Quokka specific. If I run tsc with your tsconfig file on your source file, I'm getting this output:

const a = () => Promise.resolve('a');
(() => __awaiter(this, void 0, void 0, function* () { return console.log(yield a()); }))();
//# sourceMappingURL=test.js.map

@ArtemGovorov
Copy link
Member

Have done some investigation - this is by design in TypeScript:

If the file does not have a toplevel import/export is it is not considered a module, and it is treated as script/global.

So TypeScript expects these globals for the file because the file does not look like a module to it.

If you import/export into/from the file, it'll start working as expected:

import 'path';
const a = () => Promise.resolve('a');
(async() => console.log(await a()))();

or

const a = () => Promise.resolve('a');
(async() => console.log(await a()))();
export {};

@davvit
Copy link

davvit commented Nov 8, 2017

@ArtemGovorov seems like what you found out does not help. I still get the error.

I am testing out async methods and when i call my long1() method i get the same error.

async function long1(): Promise<any> { return await new Promise((resolve) => { setTimeout(resolve, 500); console.log('long1 done'); return 1 }); }
image

@ArtemGovorov
Copy link
Member

@davvit Could you please

  • share your tsconfig.json file,
  • on a simple file like this:
import 'path';
const a = () => Promise.resolve('a');
(async() => console.log(await a()))();

run Quokka, and then run Quokka.js: Show Instrumented Code command and paste the output from the Quokka console?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants