Skip to content

πŸ“ Docs: Explain pnpm and declaration emit awkwardnessΒ #1244

@danvk

Description

@danvk

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Expected

I expected to be able to define a helper module that imported vitest without error:

import { vi } from "vitest";

export const mockError = () =>
	vi.spyOn(console, "error").mockImplementation(() => undefined);

Actual

I got an extremely cryptic error:

import { vi } from "vitest";

export const mockError = () =>
//           ~~~~~~~~~
// The inferred type of 'mockError' cannot be named without a reference to 
// '.pnpm/@[email protected]/node_modules/@vitest/spy'.
// This is likely not portable. A type annotation is necessary. ts(2742)
	vi.spyOn(console, "error").mockImplementation(() => undefined);

Additional Info

Here's an example of this error happening:

The gist seems to be that declaration: true and pnpm don't work very well together. There are many, many issues about this on the TypeScript issue tracker. The original is microsoft/TypeScript#29808.

This seems to be the canonical comment discussing workarounds: microsoft/TypeScript#47663 (comment)

In my case I just turned off .d.ts emit, though this isn't ideal.

Dropping pnpm seems a little drastic, but this isn't great and create-typescript-app pushes you towards this error with its defaults. At the very least there could be something about this in the FAQ. A link to that comment in particular would have saved me some time today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions