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

types field in package.json exports doesn't work #51862

Closed
tjx666 opened this issue Dec 12, 2022 · 3 comments
Closed

types field in package.json exports doesn't work #51862

tjx666 opened this issue Dec 12, 2022 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@tjx666
Copy link

tjx666 commented Dec 12, 2022

Bug Report

🔎 Search Terms

types, package.json, exports, import entry points

🕗 Version & Regression Information

typescript: ^4.9.4

Reproduce:

  1. git clone https://github.com/tjx666/ts-exports-development
  2. git reset --hard 70706c6845b0d8c1e55e4ab53619b91c77bcc37d
  3. pnpm install
  4. cd packages/app
  5. tsc --noEmit

⏯ Playground Link

Reproduce Repo

💻 Code

monorepo project structure:

.
├── node_modules
│   ├── tsup -> .pnpm/[email protected][email protected]/node_modules/tsup
│   └── typescript -> .pnpm/[email protected]/node_modules/typescript
├── package.json
├── packages
│   ├── app
│   │   ├── node_modules
│   │   │   └── tools -> ../../tools
│   │   ├── package.json
│   │   ├── src
│   │   │   └── index.ts
│   │   └── tsconfig.json
│   └── tools
│       ├── dist
│       │   ├── index.d.ts
│       │   ├── index.js
│       │   └── index.mjs
│       ├── package.json
│       ├── src
│       │   └── index.ts
│       └── tsconfig.json
├── pnpm-lock.yaml
└── pnpm-workspace.yaml

In packages/app/src/index.ts

// error: Cannot find module 'tools' or its corresponding type declarations
import { add } from 'tools';

console.log(add(2, 4));

In packages/tools/src/index.ts

export function add(a: number, b: number) {
    return a + b;
}

the package.json of package tools

{
    "name": "tools",
    "version": "1.0.0",
    "description": "",
    "scripts": {
        "build": "tsup src/index.ts --dts --format esm,cjs"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "exports": {
        ".": {
            "types": "./dist/index.d.ts",
            "import": {
                "development": "./src",
                "default": "./dist/index.mjs"
            },
            "require": {
                "development": "./src",
                "default": "./dist/index.js"
            }
        }
    }
}

🙁 Actual behavior

image

🙂 Expected behavior

No error

@UchihaVeha
Copy link

Same problem after the update from 4.9.3 to 4.9.4. It looks like it happened with monorepo. I am using yarn 3.3.0 workspaces

@andrewbranch andrewbranch added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 19, 2022
@andrewbranch
Copy link
Member

You are using "moduleResolution": "node" which does not support package.json exports. The value "node" represents the resolution of Node 10, which never included package.json exports support. (I recently renamed this value to "node10" in #51901.) For modern Node, you need to use "module": "node16" or "nodenext", which will also set the correct moduleResolution option that supports package.json exports and other newer resolution features.

@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants