0

I'm currently working on a React project using typescript and the bundler ParcelJs. I'm using a tsconfig.json file to configure typescript but for some reason that I don't know, Parcejs doesn't consider it ignoring all the errors on build.

For example, I wrote this code that is invalid in typescript:

const message: number = "Hello world!";

My eslint trigger this error correctly:

Type '"Hello world!"' is not assignable to type 'number'

But when I build this file using parcel ./src/index.tsx it compiles without errors.

According to the official documentation and this issue I need to declare a Validator in the ParcelJs configuration file .parcelrc:

{
    "extends": "@parcel/config-default",
    "validators": {
        "*.{ts,tsx}": ["@parcel/validator-typescript"]
    }
}

The parcel validator need to be installed in package.json:

    ...
    "dependencies": {
        "@parcel/validator-typescript": "2.0.0-nightly.112",
        ...

So at the end my project structure looks like this:

├── .cache/
├── dist/
├── src/
│   ├── index.tsx
├── .parcelrc
├── package.json
├── tsconfig.json

Note:

  • If I write invalid json data in the .parcelrc file, ParcelJs still succeeds to build without any problem as if the configuration file was ignored

Does anyone have an idea how to get ParcelJs to take into account the typescript configuration?

johannchopin
  • 13,720
  • 10
  • 55
  • 101

1 Answers1

1

I think that 2.0.0-nightly.112 was published before I made this fix. There's also this issue that bit me when I accidentally installed an older version of parcel. Can you try installing the latest nightly release of both parcel and @parcel/validator-typescript, deleting your .parcel-cache folder and trying again? If that doesn't work, would you mind sharing a repo where I could try reproducing the issue?

Another thing to try is to make sure there is a yarn.lock file in the same directory that contains the tsconfig.json. From looking at the code, I know that parcel sometimes uses this to detect the root of the project (and the tsconfig.json file). If parcel can't find a tsconfig.json file, it won't typecheck due to this issue. (If this is the root cause, it's probably something we should fix with Parcel, but it would be a good thing to test).

One other current issues with @parcel/validator-typescript that I'm working on fixing is #4204, but based on what you described, I don't think it is the cause of what you're hitting.

Andrew Stegmaier
  • 3,429
  • 2
  • 14
  • 26
  • Ok what a dumb error. My `package.json` scripts used the global version of parcel that was the version `1.12.4`. Thanks for your time and your works for the ParcelJs project :) – johannchopin Mar 17 '20 at 10:17