winnekes / itypescript

ITypescript is a typescript kernel for the Jupyter notebook (A modified version of IJavascript)
Other
190 stars 29 forks source link

Can't parse tsconfig.json but tsc can parse it #10

Open umrashrf opened 5 years ago

umrashrf commented 5 years ago

Try to put a comment in the tsconfig.json and its will complain. I would agree that it's not valid JSON file but npm/typescript can parse it

{
  "compileOnSave": true,
  "compilerOptions": {
    "lib": [
      "es2017",
      "dom"
    ],
    "outDir": "./build",
    "target": "es6",
    "module": "commonjs",
    "skipLibCheck": true, /* Try to remove it */
    "noImplicitAny": false,
    "allowJs": true,
}

After fixing the comments, I see this:

import mongoose from 'mongoose'

Error: Debug Failure. Unexpected moduleResolution: node
    at Object.resolveModuleName (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/typescript/lib/typescript.js:26281:37)
    at loader_1 (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/typescript/lib/typescript.js:86779:99)
    at loadWithLocalCache (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/typescript/lib/typescript.js:86613:42)
    at resolveModuleNamesWorker (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/typescript/lib/typescript.js:86780:123)
    at resolveModuleNamesReusingOldState (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/typescript/lib/typescript.js:87001:24)
    at processImportedModules (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/typescript/lib/typescript.js:88336:35)
    at findSourceFile (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/typescript/lib/typescript.js:88140:17)
    at /Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/typescript/lib/typescript.js:87993:85
    at getSourceFileFromReferenceWorker (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/typescript/lib/typescript.js:87960:34)
    at processSourceFile (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/typescript/lib/typescript.js:87993:13)
$ node --version
v10.15.1
$ nvm --version
0.34.0
umrashrf commented 5 years ago

8

bgnkim commented 5 years ago

This was because ITypescript resolve models by itself, not by the typescript library. I changed the code, and the issue may be resolved. Could you check whether this issue is resolved please?

bgnkim commented 5 years ago

I figured out that the incomplete parsing process of tsconfig.json file was the cause. I mistakenly believed that the function ts.readConfigFile that is currently ITypescript called for parsing configuration can convert string values into Enum values of typescript library. In a couple of minutes, I'll upload a version that the function call is replaced with ts.getParsedCommandLineOfConfigFile, which correctly handles the issue.

Note: The codes that you faced errors are tested successfully with TS 3.3, Node 10.13.0, with compilerOptions as follow ("esModuleInterop" should be true):

{
  "compileOnSave": true,
  "compilerOptions": {
    "lib": [
      "es2017",
      "dom"
    ],
    "outDir": "./build",
    "target": "es6",
    "module": "commonjs",
    "skipLibCheck": true, /* Try to remove it */
    "noImplicitAny": false,
    "allowJs": true,
    "esModuleInterop": true
  }
}