JSII compiled Python package fails in Python CDK application [ERR_PACKAGE_PATH_NOT_EXPORTED]
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 267
- Avg merge
- 1d 25m
- Merged PRs (30d)
- 14
Description
### Describe the bug
Using JSII to compile a TS/JS library into Python, and importing the library into a Python CDK application is failing when attempting to run any `cdk` commands.
The failure response returned is:
```
jsii.errors.JavaScriptError:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /var/folders/gz/.../T/jsii-kernel-ku2ecO/node_modules//package.json
```
The Library Package is created using
- jsii@1.85.0
- cdk@2.92.0
- constructs@10.1.243
The package.json contains
```json
"main": "index.js",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
},
}
```
as well as various exports of each sub-package similar to aws-cdk-lib [like so ](https://github.com/aws/aws-cdk/blob/e52acd8d449e491a60f5c78dbf7f00e333eb442c/packages/aws-cdk-lib/package.json#L219-L245)
### Expected Behavior
I expect `cdk synth` to synthesize the Python CDK code into a CloudFormation template by compiling/processing the Javascript artifact through the Python interface.
### Current Behavior
When using the JSII translated library in Python, the Interfaces are all read correctly.
However, at the time of compiling the Javascript package when running `cdk` commands... the compilation fails with the error message
```
jsii.errors.JavaScriptError:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /var/folders/gz/.../T/jsii-kernel-ku2ecO/node_modules//package.json
at new NodeError (node:internal/errors:405:5)
at exportsNotFound (node:internal/modules/esm/resolve:259:10)
at packageExportsResolve (node:internal/modules/esm/resolve:533:13)
at resolveExports (node:internal/modules/cjs/loader:571:36)
at Module._findPath (node:internal/modules/cjs/loader:645:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1058:27)
at Function.resolve (node:internal/modules/helpers:127:19)
at Kernel._Kernel_load (/private/var/folders/gz/zv011yyj62qd1rkfkx54q5zh0000gq/T/tmpqrzgy3_p/lib/program.js:10002:83)
at /private/var/folders/gz/zv011yyj62qd1rkfkx54q5zh0000gq/T/tmpqrzgy3_p/lib/program.js:9722:181
at Kernel._Kernel_debugTime (/private/var/folders/gz/zv011yyj62qd1rkfkx54q5zh0000gq/T/tmpqrzgy3_p/lib/program.js:10434:24)
```
### Reproduction Steps
## Create CDK Construct Library Using JSII
1. Create CDK Construct Library using JSII (for our use case, we have used projen and followed similar guidelines used here https://github.com/projen/projen/blob/main/docs/awscdk-construct.md)
2. Compile library package into Python using jsii-pacmak
## Import Library into Python CDK Application
1. `mkdir python-test-app` && `cd python-test-app`
2. `cdk init app --language python`
3. Install library and import into app.py with the code
```python
import library_name as foo
```
4. Run `cdk synth`
### Possible Solution
The main suspect is the package.json file, as the error clearly mentions it not containing `"exports" main`.
There is nothing within our pacakge.json that seems to be incorrect or misaligned from other libraries.
### Additional Information/Context
For security purposes, I have not included the full contents of any file. Please follow up with any questions regarding files for information.
This library has been confirmed to work for TS and Go applications, however has not worked for Python.
### SDK version used
"jsii": "~5.0.0","jsii-pacmak": "^1.83.0","aws-cdk-lib": "2.92.0", "constructs": "10.1.243","typescript": "^5.1.3"
### Environment details (OS name and version, etc.)
Mac on Venture. Python Versions 3.7, 3.8, 3.10, 3.11 using venv
Contributor guide
Research direction
Start with the generated package.json, especially its main and exports entries, and reproduce the failure using the Python CDK app steps with cdk synth. Compare the package metadata with the linked aws-cdk-lib example and inspect the jsii kernel stack around Kernel_load. Done means the translated Python library works through cdk synth without ERR_PACKAGE_PATH_NOT_EXPORTED.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, node.js, python, typescript
- Domain
- build-system, developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100