parcel icon indicating copy to clipboard operation
parcel copied to clipboard

@parcel/transformer-typescript-types: Debug Failure. Unhandled SyntaxKind: ImportClause.

Open TechQuery opened this issue 2 years ago • 11 comments

@parcel-bundler

🎛 Configuration

package.json

{
    "source": "source/index.ts",
    "types": "dist/index.d.ts",
    "module": "dist/index.esm.js",
    "main": "dist/index.js",
    "dependencies": {
        "@swc/helpers": "^0.4.11",
        "class-validator": "^0.13.2",
        "koajax": "^0.8.1",
        "reflect-metadata": "^0.1.13",
        "regenerator-runtime": "^0.13.9",
        "web-utility": "^3.9.2"
    },
    "peerDependencies": {
        "mobx": ">=4 <6"
    },
    "devDependencies": {
        "@parcel/packager-ts": "^2.7.0",
        "@parcel/transformer-typescript-types": "^2.7.0",
        "@types/node": "^14.18.26",
        "dotenv": "^16.0.1",
        "mobx": "^5.15.7",
        "parcel": "^2.7.0",
        "typescript": "~4.8.2"
    },
    "browserslist": "> 0.5%, last 2 versions, not dead, IE 11",
    "targets": {
        "main": {
            "optimize": true
        }
    },
    "scripts": {
        "build": "rm -rf dist/ docs/  &&  parcel build"
    }
}

tsconfig.json

{
    "compilerOptions": {
        "target": "ES5",
        "module": "ES6",
        "moduleResolution": "Node",
        "esModuleInterop": true,
        "downlevelIteration": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "skipLibCheck": true,
        "lib": ["ES2022", "DOM", "DOM.Iterable"]
    },
    "include": ["source/*"]
}

🤔 Expected Behavior

Build TS libraries with typescript@^4.8.0 successfully.

😯 Current Behavior

Throw an error with [email protected]:

@parcel/transformer-typescript-types: Debug Failure. Unhandled SyntaxKind: ImportClause.

but succeed with typescript@^4.7.0.

💁 Possible Solution

Support ImportClause Syntax Kind.

💻 Code Sample

idea2app/MobX-RESTful#6

🌍 Your Environment

Software Version(s)
Parcel 2.7.0
Node 14.19.1
PNPM 7.9.5
Operating System Windows 10 Pro 21H2

TechQuery avatar Aug 26 '22 12:08 TechQuery

Is this a problem caused by typescript or by @parcel/transformer-typescript-types? Is there an issue / bug ticket at typescript to follow?

levino avatar Aug 29 '22 07:08 levino

@levino I think there're Interface Breaking Changes between TS 4.7 and 4.8, which needs Parcel to adapt.

TechQuery avatar Aug 29 '22 08:08 TechQuery

Breaking Changes between TS 4.7 and 4.8

That is an oxymoron. A breaking change would have meant that typescript@5 should have been released. Maybe they do not want to clutter the versions too much but then there must be a clear list of "breaking changes" from 4.7 to 4.8. Are we sure that we are not using undocumented features / internal functions from typescript instead?

levino avatar Aug 29 '22 09:08 levino

Here are the breaking changes https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#correctness-fixes-and-breaking-changes

levino avatar Aug 29 '22 09:08 levino

That is an oxymoron. A breaking change would have meant that typescript@5 should have been released. Maybe they do not want to clutter the versions too much but then there must be a clear list of "breaking changes" from 4.7 to 4.8.

No, Typescript doesn't follow the usual semver rules, every "minor" version can also contain breaking changes, see e.g. https://github.com/microsoft/TypeScript/issues/14116

mischnic avatar Aug 29 '22 09:08 mischnic

Maybe this https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#types-cannot-be-imported-exported-in-javascript-files

levino avatar Aug 29 '22 09:08 levino

https://github.com/parcel-bundler/parcel/blob/3329469f50de9326c5b02ef0ab1c0ce41393279c/packages/transformers/typescript-types/package.json#L34 This should then rather be ~4.7. I suggest to change it.

levino avatar Aug 29 '22 09:08 levino

@levino Unfortunately, TypeScript never follows the Semantic Version specification, almost every Iteration version have breaking changes. This is not the first time I met in TypeScript ecosystem...

TechQuery avatar Aug 29 '22 10:08 TechQuery

This should then rather be ~4.7. I suggest to change it.

Well ... https://github.com/parcel-bundler/parcel/pull/6263 and https://github.com/parcel-bundler/parcel/issues/5978

mischnic avatar Aug 29 '22 11:08 mischnic

Having the same issue when trying to setup a fresh typescript react project, curiously I don't have this problem with an older react typescript project since it uses an "older" packages-lock.json

antonio-goncalves avatar Sep 03 '22 12:09 antonio-goncalves

Using the package-lock.json or yarn.lock to pin a dependency version is abusive and dangerous. An acceptable workaround is to use yarns "resolutions" field. For example in your (root when using workspaces) package.json file:

"resolutions": {
   "typescript": "~4.7"
}

levino avatar Sep 05 '22 07:09 levino

extra note:

Downgrading to TS 4.7 works. But sometimes due to package manager details, the lib still gets TS 4.8 (if it exists on another package in scope).

Also, I've noticed that the "auto-installer" was adding the extra packages to the workspace root. Try manually adding the dependencies to the child package (and removing them from the root package). Pay attention if the root package.json has been modified by parcel.

Also, Yarn seems to prefer linking 4.8 versions from other packages even if the child package has 4.7.

  "devDependencies": {
    "@parcel/packager-ts": "2.8.0",
    "@parcel/transformer-sass": "2.8.0",
    "@parcel/transformer-typescript-tsc": "^2.8.0",
    "@parcel/transformer-typescript-types": "2.8.0",
    "typescript": "4.7",

wkrueger avatar Nov 11 '22 05:11 wkrueger

Hi @devongovett , could you plz. suggest the solution to this issue. I am using pnpm workspace and TS 4.8.4, also tried the above suggestion and downgraded the TS to 4.7 still got the same issue.

shubham-kaushal avatar Nov 11 '22 10:11 shubham-kaushal

You need to pin typescript to version 4.7.x using the "resolutions" field in the root package.json as described above. @wkrueger s attempt does not work as they say themselves. If you really cannot get it to work with the "resolutions" solution, please share a demo repo where we can reproduce your issue and then I will have a look.

levino avatar Nov 14 '22 07:11 levino

If I recall I have tried resolutions but ts 4.8 still got in through from another project in the monorepo.

When yarn list showed TS 4.8 in the root project and 4.7 in the leaf project, Parcel still got 4.8. Gotta fight the module resolution a bit.

wkrueger avatar Nov 17 '22 03:11 wkrueger

Without a repo to replicate, you can only help yourself.

levino avatar Nov 17 '22 06:11 levino

You need to pin typescript to version 4.7.x using the "resolutions" field in the root package.json as described above. @wkrueger s attempt does not work as they say themselves. If you really cannot get it to work with the "resolutions" solution, please share a demo repo where we can reproduce your issue and then I will have a look.

Hi, @levino Sorry for the late response, I was unwell. Today, I am back. Thank you for the response! I was trying to migrate our tastycss repo from tsup to parcel and followed the above-suggested method still got the same error. You'll find the repo here https://github.com/OutpostHQ/tasty

I will look forward to your response.

shubham-kaushal avatar Nov 17 '22 07:11 shubham-kaushal

Lets continue this conversation in your repo.

levino avatar Nov 17 '22 08:11 levino