parcel: @parcel/transformer-typescript-types does not work

๐Ÿ› bug report

๐ŸŽ› Configuration (.babelrc, package.json, cli command)

package.json:

{
	"source": "src/index.ts",
	"module": "dist/index.js",
	"types": "dist/index.d.ts",
}

src/index.ts

export * from './src/components';

CLI: parcel build index.ts

๐Ÿค” Expected Behavior

It should build.

๐Ÿ˜ฏ Current Behavior

@parcel/transformer-typescript-types: node.exportClause.elements is not iterable
TypeError: node.exportClause.elements is not iterable
    at visit (/home/rsa/skyfall/frontend/node_modules/@parcel/transformer-typescript-types/lib/collect.js:66:47)
    at visitNodes (/home/rsa/skyfall/frontend/node_modules/typescript/lib/typescript.js:80382:48)
    at Object.visitEachChild (/home/rsa/skyfall/frontend/node_modules/typescript/lib/typescript.js:80739:56)
    at visit (/home/rsa/skyfall/frontend/node_modules/@parcel/transformer-typescript-types/lib/collect.js:112:15)
    at visitNode (/home/rsa/skyfall/frontend/node_modules/typescript/lib/typescript.js:80329:23)
    at Object.visitEachChild (/home/rsa/skyfall/frontend/node_modules/typescript/lib/typescript.js:80737:222)
    at visit (/home/rsa/skyfall/frontend/node_modules/@parcel/transformer-typescript-types/lib/collect.js:112:15)
    at visitNodes (/home/rsa/skyfall/frontend/node_modules/typescript/lib/typescript.js:80382:48)
    at visitLexicalEnvironment (/home/rsa/skyfall/frontend/node_modules/typescript/lib/typescript.js:80422:22)
    at Object.visitEachChild (/home/rsa/skyfall/frontend/node_modules/typescript/lib/typescript.js:80809:55)

๐Ÿ’ Possible Solution

๐Ÿ”ฆ Context

I just want to build this with types.

๐Ÿ’ป Code Sample

๐ŸŒ Your Environment

Software Version(s)
Parcel parcel@2.0.0-nightly.579
Node v15.9.0
npm/Yarn 1.22.10
Operating System Arch Linux

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 17
  • Comments: 28 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Any updates about this issue? Same error with "@parcel/transformer-typescript-types": "^2.4.1"

Still an issue with "@parcel/transformer-typescript-types": "^2.3.2" unfortunately

a reasonable workaround

import * as StringUtils2 from './utils/StringUtils';
export const StringUtils = {
  ...StringUtils2
}
``

Confirmed I ran in to this issue and it goes away if I comment out my usage of export * as

I tested, and #7315 doesnโ€™t address this issue, unfortunately (although it does fix #7306).

I can confirm the repro - export * as something from "./somewhere" causes the issue above. Its because we assume that if node.exportClause is defined, it will have an elements property.

https://github.com/parcel-bundler/parcel/blob/106939872e15014f45671fa971ad96fee27b2d6d/packages/transformers/typescript-types/src/collect.js#L58-L60

But if you look at the relevant typescript API types, โ€œexportsClauseโ€ could be a NamespaceExport type, in which case there will be no elements property

ExportDeclaration (code)

    export interface ExportDeclaration extends DeclarationStatement, JSDocContainer {
        // ...
        /** Will not be assigned in the case of `export * from "foo";` */
        readonly exportClause?: NamedExportBindings;
        // ...
    }

NamedExportBindings (code)

export type NamedExportBindings =
    | NamespaceExport
    | NamedExports
    ;

NamespaceExport (code)

    export interface NamespaceExport extends NamedDeclaration {
        readonly kind: SyntaxKind.NamespaceExport;
        readonly parent: ExportDeclaration;
        readonly name: Identifier
    }

So the issue is that we donโ€™t handle this case, probably because it was released after the initial implementation of @parcel/transformer-typescript-types - in Typescript 3.8 (Feb 2020)

Preliminary results show that changing the line if (node.exportClause) { to if (node.exportClause && node.exportClause.elements) { seems to work as expected. Itโ€™s correctly exporting all export * as Module from '...'; I can make a PR if anyone doesnโ€™t see anything wrong with that.

My src/components/index.ts had an export * as Icons from './Icons', and Icons.tsx exported several React components. That alone created issues with the babel transformer, a cryptic error message that unfortunately I didnโ€™t save, so I have been using the typescript-tsc which goes past that. I donโ€™t have the files in hand now, but maybe thatโ€™s related?

Yep.

Ah, I missed that comment, thanks!

So at this point this is still an open issue?

After adding tsconfig.json everything works

You can get it working by doing this:

export { default as StringUtils2 } from './utils/StringUtils'

Same error with โ€œ@parcel/transformer-typescript-typesโ€: โ€œ^2.5.0โ€

Still an issue with โ€œ@parcel/transformer-typescript-typesโ€: โ€œ^2.4.0โ€

I have exactly the same issue as @ranisalt when trying to export an Icons file on my index.ts.

Iโ€™ve tried this:

{
	"source": "index.ts",
	"types": "dist/index.d.ts",
	"scripts": {
		"build": "parcel build . --no-cache"
	},
	"dependencies": {
		"parcel": "2.0.0-nightly.579",
		"typescript": "^4.1.5"
	}
}
// index.ts
export * from './components';

// components.ts
export type Foo = string;

but it builds fine. Looks like some code in ./src/components is triggering that error (or you have a different typescript version)?