Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@parcel/transformer-typescript-types does not work #5911

Open
ranisalt opened this issue Feb 23, 2021 · 28 comments
Open

@parcel/transformer-typescript-types does not work #5911

ranisalt opened this issue Feb 23, 2021 · 28 comments

Comments

@ranisalt
Copy link
Contributor

🐛 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
@ranisalt ranisalt changed the title @parcel/transformer-typescript-tsc does not work @parcel/transformer-typescript-types does not work Feb 23, 2021
@mischnic
Copy link
Member

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)?

@ranisalt
Copy link
Contributor Author

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?

@tia-svazquez
Copy link

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

@penx
Copy link

penx commented Sep 20, 2021

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

@gruszkakarol
Copy link

I run into this issue as well whenever using export * as foo from "./foo" or export * from "./foo" syntax.

@anhpham1509
Copy link

Confirmed the same problems with export * as something from "./somewhere"

Also, the type declarations are bundled into one file incorrectly.

@anhpham1509
Copy link

#7315

I found this PR, might be it helps to sort things out.

@astegmaier
Copy link
Contributor

astegmaier commented Nov 21, 2021

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.

if (ts.isExportDeclaration(node)) {
if (node.exportClause) {
for (let element of node.exportClause.elements) {

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)

@code-and-such
Copy link

code-and-such commented Jan 7, 2022

a reasonable workaround

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

@jy95
Copy link

jy95 commented Mar 3, 2022

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

@oe
Copy link

oe commented Mar 30, 2022

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

@lucassarcanjo
Copy link

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

starpit added a commit to starpit/madwizard that referenced this issue Apr 18, 2022
We need to allow fine-grained imports, and parcel has several bugs that block doing this in the normal way:
parcel-bundler/parcel#7622
parcel-bundler/parcel#5911

This PR also enables validation and progress apis.
starpit added a commit to guidebooks/madwizard that referenced this issue Apr 18, 2022
We need to allow fine-grained imports, and parcel has several bugs that block doing this in the normal way:
parcel-bundler/parcel#7622
parcel-bundler/parcel#5911

This PR also enables validation and progress apis.
@yuuk
Copy link

yuuk commented Apr 25, 2022

Same error with "@parcel/transformer-typescript-types": "^2.5.0"

@Remeic
Copy link

Remeic commented May 3, 2022

@yuuk have you found some way to solve the issue?

@yuuk
Copy link

yuuk commented May 6, 2022

@yuuk have you found some way to solve the issue?

didn't yet

@bricejar
Copy link

Same issue here.

@pedromcunha
Copy link

You can get it working by doing this:

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

jwhitham-ds added a commit to jwhitham-ds/emoji-mart that referenced this issue Aug 10, 2022
jwhitham-ds added a commit to jwhitham-ds/emoji-mart that referenced this issue Aug 12, 2022
jwhitham-ds added a commit to jwhitham-ds/emoji-mart that referenced this issue Aug 26, 2022
@kkirby
Copy link
Contributor

kkirby commented Sep 6, 2022

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.

@ivanbanov
Copy link

As bizarre as it can sound, I was getting exact the same error because of the name of my file, in the project I have some utils, and one of them is called utils/react.ts, apparently parcel does not like the idea and throws the error 😅

🚨 Build failed.

@parcel/transformer-typescript-types: Got unexpected undefined

@ivanbanov
Copy link

Oh ok, seems like my issue was already reported #7669 👌

@PavlMais
Copy link

PavlMais commented Oct 4, 2022

After adding tsconfig.json everything works

@camdub
Copy link

camdub commented May 2, 2023

I'm still seeing this issue.

I saw a PR (#8532) from @kkirby that was closed without merging. Is there a reason that fix didn't go through?

@kkirby
Copy link
Contributor

kkirby commented May 2, 2023

@camdub I closed that for the following reason: #8532 (comment)

@camdub
Copy link

camdub commented May 2, 2023

Ah, I missed that comment, thanks!

So at this point this is still an open issue?

@kkirby
Copy link
Contributor

kkirby commented May 2, 2023

Yep.

@bergwerf
Copy link

bergwerf commented Dec 6, 2023

I'm a bit stumped this issue is still open. I'm essentially forced to either switch to another bundler (maybe Rollup) or remove the use of import * as ... from ..., which I just can't.

@Taelar
Copy link

Taelar commented Dec 14, 2023

I confirm this is still an issue, using :
"typescript": "^4.9.3"
"@parcel/transformer-typescript-types": "^2.10.3",
(I tried to upgrade to TS 5.3 but it did not seem to fix the problem)

It seems to happen when exporting types :

// MyTypes.ts
export interface Car { }
export interface Bus{ }
// index.ts
export * as Vehicles from './MyTypes.ts'

This raises the error TypeError: node.exportClause.elements is not iterable

If anyone is interested, here's my workaround. It's far from great but it works in my case :

// index.ts
import type { Car, Bus } from './MyTypes.ts'

export type Vehicles= {
  Bus: Bus
  Car: Car
}

You can then use it like this :

const myCar: Vehicles["Car"] = { }
const myBike: Vehicles["Bike"] = { } // TS Error

I'd be still very interested in a fix, as I don't like this solution so much 🙏

@kkirby
Copy link
Contributor

kkirby commented Dec 14, 2023

It seems to me that Parcel being a library bundler isn't a high priority feature. For libraries I've resorted to using tscp which is typescript with the ability to monkey patch functionality. Specifically, these two: @aliser/ts-transformer-append-js-extension and typescript-transform-paths. That way the output had the correct import paths relative to the output project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.