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

./*.d.ts required in exports to avoid Cannot be named without a reference to... not portable... #60913

Open
nemosmithasf opened this issue Jan 5, 2025 · 1 comment
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@nemosmithasf
Copy link

nemosmithasf commented Jan 5, 2025

πŸ”Ž Search Terms

The inferred type of '...' cannot be named without a reference to... This is likely not portable. A type annotation is necessary.

πŸ•— Version & Regression Information

Between 5.3 to 5.7 (latest)

⏯ Playground Link

No response

πŸ’» Code

TSconfig of importing project

{
  "compilerOptions": {
    "outDir": "./lib",
    "rootDir": "./src",
    "tsBuildInfoFile": "./lib/.tsbuildinfo",

    "target": "ESNext",
    "module":"ESNext",
    "moduleResolution":"bundler",

    "composite": true,
    "declarationMap": true,
    "sourceMap": true,
    "strict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "noErrorTruncation": true,
    "verbatimModuleSyntax": true,

    "emitDeclarationOnly": true,
    "skipLibCheck": true,

    "allowJs": true,

    
  },
  "include": ["src/**/*"]
}

Package.json of project BEING IMPORTED

{

  "type": "module",
  "files": [
    "lib/**/*",
    "src/**/*"
  ],
  "exports": {
    "./lib/*.d.ts": "./lib/*.d.ts",
    ".": {
      "types":"./lib/index.d.ts",
      "import":"./lib/index.js"
    }
  },
}

πŸ™ Actual behavior

If you do not include "./lib/*.d.ts": "./lib/*.d.ts" in the package.json of the imported project, you will receive the ...likely not portable... error.

However, in none of the documentations and searches I've seen was this written as a requirement. As a result, I assume it's a bug.

The problem with the above solution is that it exposes the .d.ts files, which causes intellisense import suggestions to suggest two imports (one from the proper path, and one from the .d.ts path).

Note:

  1. The import is a direct dependency, not a transitive dependency.
  2. Using main:./lib/index.js instead of exports:... also removes the error.

πŸ™‚ Expected behavior

Should not need to explicitly export all types

Additional information about the issue

No response

@nemosmithasf nemosmithasf changed the title ./*.d.ts required in exports to avoid "Cannot be named without a reference to... not portable..." ./*.d.ts required in exports to avoid Cannot be named without a reference to... not portable... Jan 5, 2025
@RyanCavanaugh
Copy link
Member

Please see #58176 (comment). If you have a module that is named and nameable in the current context, but see this error, please include enough information to reproduce that bug.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

2 participants