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: Got unexpected undefined #6815

Closed
jvanderen1 opened this issue Aug 29, 2021 · 19 comments
Closed

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

jvanderen1 opened this issue Aug 29, 2021 · 19 comments

Comments

@jvanderen1
Copy link

jvanderen1 commented Aug 29, 2021

🐛 bug report

I have been following the "building a library" instructions in Parcel. When adding my "types" property in package.json, I get an error message when running parcel build.

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

package.json:

{
  "name": "@jvanderen1/unstated-next",
  "version": "1.0.0",
  "description": "Up-to-date version of everyone's favorite state management library unstated-next",
  "repository": {
    "type": "git",
    "url": "https://github.com/jvanderen1/unstated-next"
  },
  "license": "MIT",
  "author": "<livetoscout@gmail.com>",
  "sideEffects": false,
  "main": "dist/unstated-next.cjs.js",
  "module": "dist/unstated-next.esm.js",
  "types": "dist/types.d.ts",
  "source": "src/index.ts",
  "scripts": {
    "build": "npm run clean:dist && parcel build",
    "clean": "npm run clean:dist && npm run clean:types && npm run clean:node-modules",
    "clean:dist": "rm -rf dist/",
    "clean:node-modules": "rm -rf node_modules/",
    "clean:types": "tsc --build --clean",
    "clean-install": "npm run clean && npm install",
    "dev": "parcel example/index.html",
    "lint": "eslint './'",
    "lint:fix": "npm run lint -- --fix",
    "prepare": "husky install",
    "pretty": "prettier --check './'",
    "pretty:fix": "prettier --write './'",
    "types-check": "tsc --skipLibCheck --noEmit"
  },
  "devDependencies": {
    "@parcel/transformer-typescript-types": "^2.0.0-rc.0",
    "@swc/cli": "^0.1.49",
    "@swc/core": "^1.2.80",
    "@types/node": "^16.7.1",
    "@types/react": "latest",
    "@types/react-dom": "latest",
    "@typescript-eslint/eslint-plugin": "^4.29.2",
    "@typescript-eslint/parser": "^4.29.2",
    "eslint": "^7.32.0",
    "eslint-plugin-react": "^7.24.0",
    "eslint-plugin-react-hooks": "^4.2.0",
    "husky": "^7.0.1",
    "lint-staged": "^11.1.2",
    "parcel": "^2.0.0-beta.3.1",
    "prettier": "^2.3.2",
    "prop-types": "latest",
    "react-dom": "latest",
    "ts-node": "^10.2.1",
    "typescript": "^4.3.5"
  },
  "peerDependencies": {
    "prop-types": ">= 15.5.0",
    "react": ">= 16.8.0"
  }
}

🤔 Expected Behavior

The parcel build command works with type definitions in dist/types.d.ts.

😯 Current Behavior

An error is thrown instead:

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

  Error: Got unexpected undefined
  at nullthrows (/Users/jvanderen1/git-projects/unstated-next/node_modules/nullthrows/nullthrows.js:7:15)
  at TSModuleGraph.propagate (/Users/jvanderen1/git-projects/unstated-next/node_modules/@parcel/transformer-typescript-types/lib/TSModuleGraph.js:265:48)
  at shake (/Users/jvanderen1/git-projects/unstated-next/node_modules/@parcel/transformer-typescript-types/lib/shake.js:42:35)
  at /Users/jvanderen1/git-projects/unstated-next/node_modules/@parcel/transformer-typescript-types/lib/TSTypesTransformer.js:138:33
  at transformation (/Users/jvanderen1/git-projects/unstated-next/node_modules/typescript/lib/typescript.js:102910:24)
  at transformRoot (/Users/jvanderen1/git-projects/unstated-next/node_modules/typescript/lib/typescript.js:102937:82)
  at Object.transformNodes (/Users/jvanderen1/git-projects/unstated-next/node_modules/typescript/lib/typescript.js:102921:78)
  at emitDeclarationFileOrBundle (/Users/jvanderen1/git-projects/unstated-next/node_modules/typescript/lib/typescript.js:103653:43)
  at emitSourceFileOrBundle (/Users/jvanderen1/git-projects/unstated-next/node_modules/typescript/lib/typescript.js:103556:13)
  at forEachEmittedFile (/Users/jvanderen1/git-projects/unstated-next/node_modules/typescript/lib/typescript.js:103264:30)

💁 Possible Solution

When attaching a debugger to parcel build, I noticed the following exception being thrown:

Screen Shot 2021-08-29 at 3 56 27 PM

After creating an empty .npmrc file in my project, I ran parcel build with the debugger again and received this exception:

Screen Shot 2021-08-29 at 3 49 21 PM

🌍 Your Environment

Software Version(s)
Parcel ^2.0.0-beta.3.1
Node 16.6.2
npm/Yarn 7.20.3
Operating System macOS 11.5.1
@mischnic
Copy link
Member

Minimal reproduction:

// index.js
import { A, B } from "./types";
export function run(a: A): B {
  return a;
}

// types.js
export * from "./a";
export type B = number;

// a.js
export type A = number;

@Shinyaigeek
Copy link
Contributor

This issue seems to be fixed in #7424 👀

@mischnic
Copy link
Member

Yes, it works correctly with a recent nightly 👍

@jvanderen1
Copy link
Author

jvanderen1 commented Dec 26, 2021

@mischnic Can you indicate which version of parcel and @parcel/transformer-typescript-types to use specifically? I pulled in ^2.0.0-nightly.952 for both and it does not work.

@mischnic
Copy link
Member

I just ran yarn add -D @parcel/packager-ts@nightly @parcel/transformer-typescript-types@nightly parcel@nightly

@jvanderen1
Copy link
Author

Thank you for the reply. I did not realize I needed to also add @parcel/packager-ts to my dependencies.

Now, I am getting an error similar to #6675. Will investigate further.

@mischnic
Copy link
Member

Now some Parcel packages are installed multiple times in various versions

@jvanderen1
Copy link
Author

So what would the recommended solution be then?

@mischnic
Copy link
Member

The easiest solution is probably removing all parcel-related entries in your lockfile.

@jvanderen1
Copy link
Author

Hmm, okay. I have deleted my package-lock.json, now I am back to the original issue:

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

  Error: Got unexpected undefined
  at nullthrows (C:\Users\livet\WebstormProjects\unstated-next\node_modules\nullthrows\nullthrows.js:7:15)
  at TSModuleGraph.propagate
  (C:\Users\livet\WebstormProjects\unstated-next\node_modules\@parcel\transformer-typescript-types\lib\TSModuleGraph.js:267:48)
  at shake (C:\Users\livet\WebstormProjects\unstated-next\node_modules\@parcel\transformer-typescript-types\lib\shake.js:42:35)
  at C:\Users\livet\WebstormProjects\unstated-next\node_modules\@parcel\transformer-typescript-types\lib\TSTypesTransformer.js:138:33
  at transformation (C:\Users\livet\WebstormProjects\unstated-next\node_modules\typescript\lib\typescript.js:107031:24)
  at transformRoot (C:\Users\livet\WebstormProjects\unstated-next\node_modules\typescript\lib\typescript.js:107058:82)
  at Object.transformNodes (C:\Users\livet\WebstormProjects\unstated-next\node_modules\typescript\lib\typescript.js:107042:78)
  at emitDeclarationFileOrBundle (C:\Users\livet\WebstormProjects\unstated-next\node_modules\typescript\lib\typescript.js:107756:43)
  at emitSourceFileOrBundle (C:\Users\livet\WebstormProjects\unstated-next\node_modules\typescript\lib\typescript.js:107659:13)
  at forEachEmittedFile (C:\Users\livet\WebstormProjects\unstated-next\node_modules\typescript\lib\typescript.js:107385:30)

With the following packages installed:

{
  "devDependencies": {
    "@parcel/packager-ts": "^2.0.0-nightly.954",
    "@parcel/transformer-typescript-types": "^2.0.0-nightly.954",
    "parcel": "^2.0.0-nightly.952",
  },
}

@jvanderen1
Copy link
Author

jvanderen1 commented Dec 26, 2021

After stepping through the code for TSModuleGraph.js and looking at the PR for #7424, it doesn't look like this nightly build contains the fix yet. This is the definition for resolveExport I receive on my end:

resolveExport(module, name) {
    for (let e of module.exports) {
      if (e.name === name) {
        return this.getExport(module, e);
      } else if (e.specifier) {
        return this.resolveExport((0, _nullthrows().default)(this.getModule(e.specifier)), name);
      }
    }
  }

I will inject the fix from #7424 manually and see if that resolves my issue.

@jvanderen1
Copy link
Author

Manually editing TSModuleGraph.js seems to have resolved my issue 👍🏻:

resolveExport(module, name) {
    for (let e of module.exports) {
      if (e.name === name) {
        return this.getExport(module, e);
      } else if (e.specifier) {
        const m = this.resolveExport((0, _nullthrows().default)(this.getModule(e.specifier)), name);
        if (m) { return m; }
      }
    }
  }

I advise the parcel team to explicitly specify a version for these fixes for others who may run across this issue.

@jvanderen1
Copy link
Author

I found another issue with generated types and have created another issue here: #7488

@boaz-codota
Copy link

Hey @mischnic maybe you should re-open this issue? I'm experiencing the same thing trying to use percel.

@mischnic
Copy link
Member

mischnic commented Jan 3, 2022

Have you tried the nightly version? #6815 (comment)

@ul
Copy link

ul commented Jan 7, 2022

I'm experiencing the issue with the latest nightly version:

    "@parcel/packager-ts": "^2.0.0-nightly.970",
    "@parcel/transformer-typescript-types": "^2.0.0-nightly.970",
    "parcel": "^2.0.0-nightly.968",

@andreascful
Copy link

andreascful commented Jan 17, 2022

I'm also experiencing the same issue with the current nightly.982 (and of course also the current stable 2.2.0)

@millievn
Copy link

same issue here with these dependences:

    "@parcel/packager-ts": "^2.2.1",
    "@parcel/transformer-typescript-types": "^2.2.1",
    "@types/node": "^10.12.15",
    "parcel": "^2.2.1",
    "typescript": "^3.9.7"

@arimariojesus
Copy link

arimariojesus commented Feb 24, 2022

I'm experiencing the same issue with these dependences:

  "@parcel/packager-ts": "^2.3.2",
    "@parcel/transformer-typescript-types": "^2.3.2",
    "parcel": "^2.3.2",
    "typescript": "^4.5.5"

Is there a solution to fix it?

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

No branches or pull requests

8 participants