DonJayamanne / typescript-notebook

Run JavaScript and TypeScript in node.js within VS Code notebooks with excellent support for debugging, tensorflowjs visulizations, plotly, danfojs, etc
https://marketplace.visualstudio.com/items?itemName=donjayamanne.typescript-notebook
MIT License
910 stars 40 forks source link

TSError: ⨯ Unable to compile TypeScript: #38

Open KhanhPham2411 opened 3 years ago

KhanhPham2411 commented 3 years ago

I got this error when trying to import my code:

TSError: ⨯ Unable to compile TypeScript:
signal.ts(8,28): error TS2583: Cannot find name 'Promise'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.
signal.ts(10,18): error TS2552: Cannot find name 'Date'. Did you mean 'date'?
signal.ts(24,20): error TS2304: Cannot find name 'Date'.
c:\Users\Khanh\.vscode\extensions\donjayamanne.typescript-notebook-2.0.3\resources\scripts\node_modules\ts-node\dist\index.js:289
            throw error;
            ^

    at createTSError (c:\Users\Khanh\.vscode\extensions\donjayamanne.typescript-notebook-2.0.3\resources\scripts\node_modules\ts-node\src\index.ts:692:12)
    at reportTSError (c:\Users\Khanh\.vscode\extensions\donjayamanne.typescript-notebook-2.0.3\resources\scripts\node_modules\ts-node\src\index.ts:696:19)
    at getOutput (c:\Users\Khanh\.vscode\extensions\donjayamanne.typescript-notebook-2.0.3\resources\scripts\node_modules\ts-node\src\index.ts:883:36)
    at Object.compile (c:\Users\Khanh\.vscode\extensions\donjayamanne.typescript-notebook-2.0.3\resources\scripts\node_modules\ts-node\src\index.ts:1185:30)
    at Module.m._compile (c:\Users\Khanh\.vscode\extensions\donjayamanne.typescript-notebook-2.0.3\resources\scripts\node_modules\ts-node\src\index.ts:1309:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Object.require.extensions.<computed> [as .ts] (c:\Users\Khanh\.vscode\extensions\donjayamanne.typescript-notebook-2.0.3\resources\scripts\node_modules\ts-node\src\index.ts:1313:12)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Function._._load (c:\Users\Khanh\.vscode\extensions\donjayamanne.typescript-notebook-2.0.3\out\extension\server\index.js:2:115324)

image

Any suggestion to fix it would be appreciated

DonJayamanne commented 3 years ago

What version of node do you have installed?

KhanhPham2411 commented 3 years ago

Hi Don,

Thanks for looking into this, please take a look at this replicated minimal code:

export class Test {
  static async getDate(a, b){
    return new Promise((resolve) => {
      resolve(new Date().valueOf());
    });
  }
}

image

I am using Node v14.17.0

DonJayamanne commented 3 years ago

I believe the problem is because you don't have typescript installed. When importing external typescript files, you might have to isntall typescript in your project folder. Please could you try that for now.

I'll see what can be done to get this working without installing typescript (for external files)

@KhanhPham2411 Please let me know if that works (as a temporary work around)

dinofx commented 2 years ago

Your TS code must be in a location where ts-node can find a tsconfig.json file for it. For example, in the same or parent folder:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "ES2019",
  }
}

Setting the target implicitly sets the lib values