jsii icon indicating copy to clipboard operation
jsii copied to clipboard

jsii-config produces non working configuration

Open ganeshltimindtree opened this issue 1 year ago • 10 comments

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

ganeshltimindtree avatar Nov 10 '24 06:11 ganeshltimindtree

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.

gankumaraamc avatar Nov 15 '24 14:11 gankumaraamc

Note that it is converting TypeScript to JavaScript but Java or Python code is not generated.

gankumaraamc avatar Nov 15 '24 14:11 gankumaraamc

Double checking: C:\Workspace\internal\jsii-getting-started\index.ts does exist?

mrgrain avatar Nov 18 '24 09:11 mrgrain

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.

mrgrain avatar Nov 18 '24 10:11 mrgrain

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.

mrgrain avatar Nov 18 '24 10:11 mrgrain

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"

gankumaraamc avatar Nov 18 '24 12:11 gankumaraamc

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.

mrgrain avatar Nov 18 '24 13:11 mrgrain

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/

gankumaraamc avatar Nov 18 '24 14:11 gankumaraamc

Thanks that's helpful. Looks like jsii-config is not producing the right thing. Moving back to the correct repo and updating title.

mrgrain avatar Nov 19 '24 18:11 mrgrain

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.

LeeAdcock avatar Dec 21 '24 17:12 LeeAdcock