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 throws a "Got unexpected undefined" error when using a re-exported type #7360

Closed
jakeboone02 opened this issue Nov 24, 2021 · 9 comments · Fixed by #7424

Comments

@jakeboone02
Copy link

🐛 bug report

@parcel/transformer-typescript-types throws a Got unexpected undefined error when using a re-exported type/interface in a React component. I'm not sure that's the root cause but it's the only way I can reproduce the erro consistently.

In this minimal example repo, look at the src/controls/ValueEditor.tsx file, which has a working line (commented out) and a non-working line. Both lines should work.

🎛 Configuration (.babelrc, package.json, cli command)

Running yarn build throws the error, even after deleting .parcel-cache. I do not have a .babelrc.

package.json:

{
  "name": "parcel-basic-test",
  "version": "1.0.0",
  "private": true,
  "source": "src/index.ts",
  "main": "dist/index.js",
  "module": "dist/index.esm.js",
  "types": "dist/types.d.ts",
  "license": "MIT",
  "devDependencies": {
    "@parcel/packager-ts": "^2.0.1",
    "@parcel/transformer-typescript-types": "^2.0.1",
    "@types/react": "^17.0.36",
    "parcel": "^2.0.1",
    "react": "^17.0.2",
    "rimraf": "^3.0.2",
    "typescript": "^4.5.2"
  },
  "peerDependencies": {
    "react": ">=16.8.0",
    "react-dom": ">=16.8.0"
  },
  "scripts": {
    "build": "rimraf dist && parcel build"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2021",
    "jsx": "react-jsx",
    "module": "ES6",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "strict": true,
    "skipLibCheck": true
  }
}

🤔 Expected Behavior

Parcel should not error out.

😯 Current Behavior

PS C:\Users\jaboone\git\parcel-basic-test> rm -r .\.parcel-cache\ && yarn build
yarn run v1.22.17
$ rimraf dist && parcel build
× Build failed.

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

  Error: Got unexpected undefined
  at nullthrows (C:\Users\jaboone\git\parcel-basic-test\node_modules\nullthrows\nullthrows.js:7:15)
  at TSModuleGraph.propagate (C:\Users\jaboone\git\parcel-basic-test\node_modules\@parcel\transformer-typescript-types\lib\TSModuleGraph.js:267:48)
  at shake (C:\Users\jaboone\git\parcel-basic-test\node_modules\@parcel\transformer-typescript-types\lib\shake.js:42:35)
  at C:\Users\jaboone\git\parcel-basic-test\node_modules\@parcel\transformer-typescript-types\lib\TSTypesTransformer.js:138:33
  at transformation (C:\Users\jaboone\git\parcel-basic-test\node_modules\typescript\lib\typescript.js:107012:24)
  at transformRoot (C:\Users\jaboone\git\parcel-basic-test\node_modules\typescript\lib\typescript.js:107039:82)
  at Object.transformNodes (C:\Users\jaboone\git\parcel-basic-test\node_modules\typescript\lib\typescript.js:107023:78)
  at emitDeclarationFileOrBundle (C:\Users\jaboone\git\parcel-basic-test\node_modules\typescript\lib\typescript.js:107737:43)
  at emitSourceFileOrBundle (C:\Users\jaboone\git\parcel-basic-test\node_modules\typescript\lib\typescript.js:107640:13)
  at forEachEmittedFile (C:\Users\jaboone\git\parcel-basic-test\node_modules\typescript\lib\typescript.js:107366:30)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

💁 Possible Solution

N/A

🔦 Context

Trying to migrate the react-querybuilder repo from webpack to Parcel + monorepo. See parcel branch for current attempt.

💻 Code Sample

Example repo. Clone, cd to the new folder, then run yarn && yarn build.

🌍 Your Environment

Software Version(s)
Parcel 2.0.1
Node 16.13.0
npm/Yarn 1.22.17
Operating System any (fails on all)
@olipyskoty
Copy link

Hey! I also received this same error, though I don't have the slightest clue where it is coming from.

@jakeboone02 I was able to bypass this error by following the workaround in the description for #5735 listed here. For some reason by adding the following to my package.json I no longer receive the error:

  "types": "index.d.ts",
  "targets": {
    "types": false
  },

Again, not sure why this fixes it, but I figured it might be able to help you out as this issue gets investigated.

@jakeboone02
Copy link
Author

Thanks @olipyskoty, but doesn't that prevent the types from being generated at all?

@tylim88
Copy link

tylim88 commented Feb 25, 2022

is this problem solved, I still having similar issue here

parcel 2.3.2

setting target type to false works but we need the declaration file

@elijahmontenegro
Copy link

elijahmontenegro commented May 26, 2022

this is still an issue for me using parcel 2.5.0

EDIT:
Fixed for me. The issue was my other parcel dependencies (specifically @parcel/packager-ts) were not in line with my parcel version. I also incremented to version 2.6.0 where I had the same issue before fixing the versions.

@steve-taylor
Copy link

Still fails in 2.6.2.

🚨 Build failed.

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

  Error: Got unexpected undefined
      at nullthrows (/path/to/monorepo/node_modules/nullthrows/nullthrows.js:7:15)
      at TSModuleGraph.propagate (/path/to/monorepo/node_modules/@parcel/transformer-typescript-types/lib/TSModuleGraph.js:271:48)
      at shake (/path/to/monorepo/node_modules/@parcel/transformer-typescript-types/lib/shake.js:42:35)
      at /path/to/monorepo/node_modules/@parcel/transformer-typescript-types/lib/TSTypesTransformer.js:148:33
      at transformation (/path/to/monorepo/node_modules/typescript/lib/typescript.js:109638:24)
      at transformRoot (/path/to/monorepo/node_modules/typescript/lib/typescript.js:109665:82)
      at Object.transformNodes (/path/to/monorepo/node_modules/typescript/lib/typescript.js:109649:78)
      at emitDeclarationFileOrBundle (/path/to/monorepo/node_modules/typescript/lib/typescript.js:110363:43)
      at emitSourceFileOrBundle (/path/to/monorepo/node_modules/typescript/lib/typescript.js:110266:13)
      at forEachEmittedFile (/path/to/monorepo/node_modules/typescript/lib/typescript.js:109992:30)

@kre1z0
Copy link

kre1z0 commented Jul 9, 2022

Do not use global types from d.ts source declare in typescript files like a

use global.ts not global.d.ts without import

declare global {
  interface Window {};
  type ValueOf<T> = T[keyof T];
}

@mxmvshnvsk
Copy link

parcel@2.7.0 @parcel/transformer-typescript-types@2.7.0 still fails, any solutions?

@lucasruy
Copy link

Hey! I also received this same error, though I don't have the slightest clue where it is coming from.

@jakeboone02 I was able to bypass this error by following the workaround in the description for #5735 listed here. For some reason by adding the following to my package.json I no longer receive the error:

  "types": "index.d.ts",
  "targets": {
    "types": false
  },

Again, not sure why this fixes it, but I figured it might be able to help you out as this issue gets investigated.

Even if there is no explanation for this, thanks for sharing as it helped me to solve this problem in my project.

@mischnic
Copy link
Member

explanation

This just completely disables the generation of a types file in Parcel. So you'll have to write index.d.ts yourself or generate it by some other means.

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.

9 participants