jsii-config produces non working configuration
Describe the bug
I am getting started with jsii. I facing an issue when running npm run build. Below is my jsii configuration as created by jsii-config
"...",
"keywords": [],
"author": {
"name": "Ganesh Kumar",
"email": "[email protected]"
},
"repository": {
"url": "https://github.com/ganesh/jsii-getting-started.git"
},
"license": "ISC",
"stability": "stable",
"types": "index.d.ts",
"jsii": {
"versionFormat": "full",
"targets": {
"java": {
"package": "com.ganesh.learn.jsii",
"maven": {
"groupId": "com.ganesh.learn",
"artifactId": "jsii"
}
}
},
"tsc": {
"outDir": "dist"
}
},
"devDependencies": {
"jsii": "^5.5.9",
"jsii-pacmak": "^1.104.0"
}
}
The error I am getting is
[2024-11-10T12:04:33.432] [ERROR] jsii/compiler - Type model errors prevented the JSII assembly from being created error JSII4: Could not find "main" file: C:\Workspace\internal\index.ts
The project is in C:\Workspace\internal\jsii-getting-started. It seems jsii is looking at the parent directory rather than the project directory.
Regression Issue
- [ ] Select this option if this issue appears to be a regression.
Expected Behavior
jsii should generate Java files
Current Behavior
I am getting this error
[2024-11-10T12:04:33.432] [ERROR] jsii/compiler - Type model errors prevented the JSII assembly from being created error JSII4: Could not find "main" file: C:\Workspace\internal\index.ts
Reproduction Steps
Follow the steps listed in the documentation to create a sample project. Run the command npm run build. You will get the error in Windows 11 enterprise
Possible Solution
None
Additional Information/Context
No response
SDK version used
jsii: 5.5.9 & jsii-pacmak: 1.104.0
Environment details (OS name and version, etc.)
Windows 11 Enterprise
I tried this one in mac(macOS 15) to check if works. I am getting the same error. Just wondering if I am missing anything in the documentation.
Note that it is converting TypeScript to JavaScript but Java or Python code is not generated.
Double checking: C:\Workspace\internal\jsii-getting-started\index.ts does exist?
When I'm trying to reproduce, I'm getting the error:
[ERROR] The "package.json" file must specify the "main" attribute
Can you please post the complete package.json file including your main attribute.
Ideally you can share a complete minimal example.
Okay, I can reproduce this now. The error is wrong and misleading due to the wrong path being referenced.
But basically these two lines conflict with each other:
"types": "index.d.ts",
"jsii": {
"tsc": {
"outDir": "dist"
}
},
The TypeScript configuration (jsii.tsc.outDir) says that all files will be places into a dist directory.
However the types line tells us to look for the file <project-root>/index.d.ts, which doesn't exists.
Instead set the following and it should all work:
"types": "dist/index.d.ts",
Keeping this open since the error is clearly wrong.
Thanks @mrgrain. Correcting index.d.ts path to include dist fixes the error. npm run build is successful. But jsii-pacmak does not work. It throws this error -
Error: Invalid "jsii" section in C:\Workspace\internal\jsii-getting-started. Expecting "outdir" and "targets"
No worries @gankumaraamc
jsii-pacmak indeed requires jsii.outdir to be set (note the lowercase d). The build works because jsii (the compiler) doesn't need this field, only jsii-pacmak does.
Typically jsii.outdir and jsii.tsc.outDir would be set at different values. A common config looks like this:
"types": "lib/index.d.ts",
"jsii": {
"outdir": "dist",
"tsc": {
"outDir": "lib"
}
},
Now I'm guessing you came to your original config following our docs and they are incorrect or missing some important parts. Could you share what docs or tutorials you have been following? I'd like to fix these.
Sure, I followed the getting started doc available in the jsii site - https://aws.github.io/jsii/user-guides/lib-author/quick-start/set-up/
Thanks that's helpful. Looks like jsii-config is not producing the right thing. Moving back to the correct repo and updating title.
I was also tripped up by the missing outdir required on jsii configuration. In addition to adding this to the sample, I would suggest we get it into the documentation as well. There will be some inevitable confusion on the case sensitive difference with tsc config's outDir having an uppercase D.