这是indexloc提供的服务,不要输入任何密码
Skip to content

📚 Docs: Expand on subpath imports #10949

@borisghidaglia

Description

@borisghidaglia

What is the improvement or update you wish to see?

A more elaborate example of using subpath imports.

Wrote my experience below. If it is not a skill issue, I think it would be worth adding!

Thanks and have a nice day/evening,

Boris

Is there any context that might help us understand?

Starting from the current raw pnpm dlx create-turbo@latest install and following the Crafting your repository part of the doc, at one point subpath imports are mentioned.

Currently, it points to the Node.js doc and to the Use Node.js subpath imports instead of TypeScript compiler paths section of the doc.

But by just adding the recommended imports to the packages/ui/package.json, we can't use subpath imports yet.

{
  "imports": {
    "#*": "./src/*"
  }
}

Indeed, by importing Card from button we get an error: Cannot find module '#card' or its corresponding type declarations.

import { Card } from "#card";

To fix it, we need to add .js, not ideal.

import { Card } from "#card.js";

But then when running pnpm check-types we get into another problem: error TS2210: The project root is ambiguous, but is required to resolve import map entry 'card.js' in file '/Users/boris/Documents/Clients/Scienta/my-turborepo/packages/ui/package.json'. Supply the rootDir compiler option to disambiguate.

So we add rootDir in packages/ui/package.json

  "compilerOptions": {
    ...
    "rootDir": "src"
  },

And if we want to get rid of the .js from above, we have to do:

  "imports": {
    "#*": "./src/*.js"
  },

Does the docs page already exist? Please link to it.

https://turborepo.com/docs/guides/tools/typescript#use-nodejs-subpath-imports-instead-of-typescript-compiler-paths

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: docsImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions