Skip to content

(rosetta) Cannot reference package by its own name #3654

Description

@mrgrain

Describe the bug

When importing modules from the current package, rosetta doesn't accept the package name, but instead requires the use of a path.

For a hypothetical package some-library:

# Fails with: error TS2307: Cannot find module 'some-library' or its corresponding type declarations.
import * as myLib from 'some-library';

# This works and is translated to the above line for TypeScript
import * as myLib from '.';

For examples and inline docs this might be "good enough", especially if imports are hidden away in a fixture. However in READMEs it's often desired to include a full example including imports. In this case, I'd want to import my package by it's public name. Furthermore in a README I cannot use directives or void statements as they would be visible to the user.

Interestingly, including the package in exampleDependencies doesn't work either.

Expected Behavior

I can reference the current package by its name in Rosetta examples:

# This should work
import * as myLib from 'some-library';

Current Behavior

The above example fails with:

error TS2307: Cannot find module 'some-library' or its corresponding type declarations.

Reproduction Steps

  • Create a new jsii package some-library, e.g. with projen.
  • Add an export: SomeClass
  • Add this example to the README.md
# This should work
import * as myLib from 'some-library';

new myLib.SomeClass();
  • Run npx jsii-rosetta extract

Possible Solution

No response

Additional Information/Context

The current docs don't make it very clear how to refer to uses names from the current package.
import * as myLib from '.' works but is not documented.

SDK version used

1.69.0

Environment details (OS name and version, etc.)

WSL2 Ubuntu

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions