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]: Meaningless "Got unexpected undefined" error message #7669

Open
jakubmazanec opened this issue Feb 7, 2022 · 15 comments

Comments

@jakubmazanec
Copy link

I encountered "Got unexpected undefined" error. I don't know what exactly causes it, but I created repo with minimal reproduction.

🎛 Configuration

package.json

{
  "name": "parcel-bug",
  "main": "dist/index.js",
  "source": "src/index.ts",
  "types": "dist/index.d.ts",
  "scripts": {
    "build": "parcel build"
  },
  "dependencies": {
    "next": "^12.0.10"
  },
  "devDependencies": {
    "@parcel/packager-ts": "^2.2.1",
    "@parcel/transformer-typescript-types": "^2.2.1",
    "parcel": "^2.2.1",
    "typescript": "^4.5.5"
  }
}

tsconfig.json

{
  "extends": "./tsconfig.options.json",
  "compilerOptions": {
    "composite": true,
    "esModuleInterop": true,
    "exactOptionalPropertyTypes": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "react-jsx",
    "lib": ["DOM", "DOM.Iterable", "ES2021"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmit": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noUncheckedIndexedAccess": true,
    "rootDir": "./src",
    "strict": true,
    "target": "ES2021",
  },
  "include": ["src/**/*"],
  "references": []
}

Source code:

import type { NextWebVitalsMetric } from 'next/app';

declare module 'next/app' {
  export interface AppInitialProps {
    pageProps: unknown;
  }
}

export async function reportWebVitals({ value, name }: NextWebVitalsMetric) {}

🤔 Expected Behavior

Parcel builds with no error? I think this minimal reproduction shouldn't actually build (because of e.g. missing React), but the errors should be more descriptive and useful.

😯 Current Behavior

Parcel errors:

× Build failed.

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

  Error: Got unexpected undefined
  at nullthrows (D:\projects\parcel-test\node_modules\nullthrows\nullthrows.js:7:15)
  at TSModuleGraph.propagate
  (D:\projects\parcel-test\node_modules\@parcel\transformer-typescript-types\lib\TSModuleGraph.js:271:48)
  at shake (D:\projects\parcel-test\node_modules\@parcel\transformer-typescript-types\lib\shake.js:42:35)
  at D:\projects\parcel-test\node_modules\@parcel\transformer-typescript-types\lib\TSTypesTransformer.js:139:33
  at transformation (D:\projects\parcel-test\node_modules\typescript\lib\typescript.js:107043:24)
  at transformRoot (D:\projects\parcel-test\node_modules\typescript\lib\typescript.js:107070:82)
  at Object.transformNodes (D:\projects\parcel-test\node_modules\typescript\lib\typescript.js:107054:78)
  at emitDeclarationFileOrBundle (D:\projects\parcel-test\node_modules\typescript\lib\typescript.js:107768:43)
  at emitSourceFileOrBundle (D:\projects\parcel-test\node_modules\typescript\lib\typescript.js:107671:13)
  at forEachEmittedFile (D:\projects\parcel-test\node_modules\typescript\lib\typescript.js:107397:30)

💻 Code Sample

Repo with reproduction. Clone and run npm install and npm run build.

🌍 Your Environment

Software Version(s)
Parcel 2.2.1
Node 16.13.2
npm 8.3.1
Operating System Windows 10 Enterprise 20H2
@zapplebee
Copy link

node.modifiers.unshift(ts.createModifier(ts.SyntaxKind.DeclareKeyword));

With the debugger, it looks like here is the node remains undefined.

@rathpc
Copy link

rathpc commented Apr 4, 2022

I also ran into this issue recently although slightly different

@parcel/transformer-typescript-types: Cannot read properties of undefined (reading 'unshift')
  TypeError: Cannot read properties of undefined (reading 'unshift')

the modifiers on the node in my case was undefined and I have found that this is only introduced when you have a typescript version >= 4.6.0.

@jakubmazanec I notice you have "typescript": "^4.5.5" can you take a look in your yarn.lock/package-lock.json and see what version is actually in your project? I suspect if you explicitly set a version like "typescript": "4.5.5" your problem might go away like mine did.

This does however not explain the problem since that is a minor version bump of TS and I would have expected a library depending on that to not be affected. If it is, then I think this lib needs a strict version associated to prevent this issue until the code causing the error is updated with the newer version of TS.

@jakubmazanec
Copy link
Author

jakubmazanec commented Apr 4, 2022

@rathpc I reported this 2 months ago, when TypeScript 4.6 wasn't released yet. But I'll try anyway.

@jakubmazanec
Copy link
Author

I installed and run the repo with TypeScript 4.6.3 and also with TypeScript 4.5.5, same error.

Best if somebody took a look at that PR...

@rathpc
Copy link

rathpc commented Apr 4, 2022

I installed and run the repo with TypeScript 4.6.3 and also with TypeScript 4.5.5, same error.

Best if somebody took a look at that PR...

Ah ok, thanks for testing my theory at least!

@gradddev
Copy link

gradddev commented Apr 22, 2022

I got the same error. Don't know is it the same bug or not, but I figured out the following:

  1. Let's import some type from some npm package:
// index.ts
import { FC } from "react";
  1. Use this type and export:
// index.ts
export type MyComponent = FC<{}>;
  1. Create a file with the same name of the module in the first step:
// react.ts
export default "";
  1. Try to import something from the file that created in the third step:
// index.ts
import { FC } from "react";

// @parcel/transformer-typescript-types: Got unexpected undefined
import {} from "./react";

export type MyComponent = FC<{}>;

It also works with other modules. React is just an example.

Versions:

  • parcel: 2.5.0
  • @parcel/transformer-typescript-types: 2.5.0
  • @parcel/packager-ts: 2.5.0
  • typescript: 4.6.3
  • node: 17.8.0

Repo with reproduction: https://github.com/alexgraddev/parcel2-typescript-types-bug

@danieltroger
Copy link
Contributor

Would also appreciate a fix for this!

@Swizec
Copy link

Swizec commented Aug 25, 2022

I ran into this problem and figured out what the error means. So at least I can fix it in user-land code, but a more helpful message would be nice.

It happens when you get a squiggly line on a type import.

CleanShot 2022-08-25 at 15 42 34@2x

@Swizec
Copy link

Swizec commented Aug 25, 2022

Also looks like there's something with index re-exports

this doesn't work:

// src/index.ts
import { customTheme } from './themes'

// src/themes/index.ts
export * from './customTheme'

// src/themes/customTheme.ts
export const customTheme = ...

this works:

// src/index.ts
import { customTheme } from './themes/customTheme'

// src/themes/index.ts
export * from './customTheme'

// src/themes/customTheme.ts
export const customTheme = ...

@ivanbanov
Copy link

I had the same problem that was mentioned here #7669 (comment), and found another issue when renaming it.

Name Works
react
_react
react_

It seems like leading _ is not welcome 🤔

@ted-palmer
Copy link

I'm having the same problem. Here is a reproducible repo. Would love if this could get resolved, or if anyone has any solutions. Thanks!

@github-actions github-actions bot added the Stale Inactive issues label Aug 29, 2023
@danieltroger
Copy link
Contributor

I'm still seeing this every now and then, don't think it has been resolved

@github-actions github-actions bot removed the Stale Inactive issues label Aug 29, 2023
@jakubmazanec
Copy link
Author

jakubmazanec commented Oct 19, 2023

I updated all dependencies in the repo with the bug reproduction; the bug still exists.

@github-actions github-actions bot added the Stale Inactive issues label Apr 17, 2024
@jakubmazanec
Copy link
Author

I updated Parcel and TypeScript in the repo with the bug reproduction; the bug still exists.

@github-actions github-actions bot removed the Stale Inactive issues label Apr 17, 2024
@github-actions github-actions bot added the Stale Inactive issues label Oct 14, 2024
@danieltroger
Copy link
Contributor

I assume this is still not fixed?

@github-actions github-actions bot removed the Stale Inactive issues label Oct 14, 2024
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