jsii icon indicating copy to clipboard operation
jsii copied to clipboard

(rosetta) Cannot reference package by its own name

Open mrgrain opened this issue 2 years ago • 0 comments

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

mrgrain avatar Oct 16 '22 22:10 mrgrain