fathyb / parcel-plugin-typescript

🚨 Enhanced TypeScript support for Parcel
MIT License
180 stars 18 forks source link

Comments in tsconfig are not supported #45

Open giyyapan opened 6 years ago

giyyapan commented 6 years ago

Hi all,

The default typescript loader works fine for me, but after I install parcel-plugin-typescript and restart parcel, this error appear. (and no type check result )

Server running at http://localhost:1234 
✨  Built in 665ms.
⚠️  Unexpected token }
    at unexpected (/home/giyya/[path-to-project]/node_modules/json-parser/index.js:121:9)
    at expect (/home/giyya/[path-to-project]/node_modules/json-parser/index.js:115:5)
    at parse_object (/home/giyya/[path-to-project]/node_modules/json-parser/index.js:140:5)
    at walk (/home/giyya/[path-to-project]/node_modules/json-parser/index.js:91:14)
    at parse_object (/home/giyya/[path-to-project]/node_modules/json-parser/index.js:148:33)
    at walk (/home/giyya/[path-to-project]/node_modules/json-parser/index.js:91:14)
    at Object.parse (/home/giyya/[path-to-project]/node_modules/json-parser/index.js:55:16)
    at Object.parse (/home/giyya/[path-to-project]/node_modules/comment-json/lib/parse.js:8:17)
    at Object.<anonymous> (/home/giyya/[path-to-project]/node_modules/parcel-plugin-typescript/build/backend/config-loader.js:25:37)
    at Generator.next (<anonymous>)

This is my tsconfig.json:

{
  "compilerOptions": {
    "sourceMap": true,
    "alwaysStrict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "strict": true,
    "strictNullChecks": false,
    "noFallthroughCasesInSwitch": true,
    "experimentalDecorators": true,
    "target": "es5",
    "module": "es2015",
    "baseUrl": "./ts",
    "outDir": "./js",
    "moduleResolution": "classic",
  },
  "parcelTsPluginOptions": {
    // If true type-checking is disabled
    "transpileOnly": false
  },
  "compileOnSave": false
}

Let me know if you need more information.

raould commented 6 years ago

hi,

versions: node v8.11.3 windows 7 pro x64 my versions in package.json are:

    "devDependencies": {
        "@types/socket.io": "^1.4.0",
        "parcel": "^1.9.7",
        "parcel-plugin-typescript": "^1.0.0",
        "typescript": "^2.9.2"
    },
    "dependencies": {
        "phaser": "^3.11.0",
        "socket.io": "^1.4.0"
    }

my tsconfig.json, which might be horrible since i am new to typescript, and especially because i guess i have to try to base it off of parcel's hidden internal default? At any rate, when i do "tsc -p ." i do not get any errors fwiw.

{
    "compilerOptions": {
        "pretty": false,
        "module": "commonjs",
        "esModuleInterop": true,
        "jsx": "preserve",
        "baseUrl": "./src",
        "paths": {
            "src/*": ["./src/*"],
        },
        "noEmit": false,
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "strict": true,
    },
    "include": [
        "src/**/*.ts",
        "lib/types/phaser.comments.d.ts"
    ],
    "exclude": [
        "node_modules"
    ],
}
gabriofr commented 6 years ago

Had the same problem (without comments in the tsconfig.json), got rid of it by adding an empty "parelTsPluginOptions under compileroptions.

Like so: "parcelTsPluginOptions": {}

gabriofr commented 6 years ago

On further inspection a trailing comma from inside the compilerOptions might be what caused this. Removed the line I mentioned above and a trailing comma and the "Unexpected token }" error is now gone.

@raould : try to change your config to this:

{
  "compilerOptions": {
    "pretty": false,
    "module": "commonjs",
    "esModuleInterop": true,
    "jsx": "preserve",
    "baseUrl": "./src",
    "paths": {
      "src/*": ["./src/*"]
    },
    "noEmit": false,
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true,
    "strict": true
  },
  "include": ["src/**/*.ts", "lib/types/phaser.comments.d.ts"],
  "exclude": ["node_modules"]
}