Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsii-config produces non working configuration #4705

Open
1 task
ganeshltimindtree opened this issue Nov 10, 2024 · 10 comments
Open
1 task

jsii-config produces non working configuration #4705

ganeshltimindtree opened this issue Nov 10, 2024 · 10 comments
Labels
bug This issue is a bug. p1

Comments

@ganeshltimindtree
Copy link

ganeshltimindtree commented Nov 10, 2024

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": "ganesh.kumar@acme.com"
  },
  "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 ganeshltimindtree added the bug This issue is a bug. label Nov 10, 2024
@gankumaraamc
Copy link

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
Copy link

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

@mrgrain mrgrain transferred this issue from aws/jsii Nov 18, 2024
@mrgrain
Copy link
Contributor

mrgrain commented Nov 18, 2024

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

@mrgrain mrgrain added the p1 label Nov 18, 2024
@mrgrain
Copy link
Contributor

mrgrain commented Nov 18, 2024

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
Copy link
Contributor

mrgrain commented Nov 18, 2024

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.

@gankumaraamc
Copy link

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"

@mrgrain
Copy link
Contributor

mrgrain commented Nov 18, 2024

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.

@gankumaraamc
Copy link

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/

@mrgrain
Copy link
Contributor

mrgrain commented Nov 19, 2024

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

@mrgrain mrgrain transferred this issue from aws/jsii-compiler Nov 19, 2024
@mrgrain mrgrain changed the title error JSII4: Could not find "main" file: jsii-config produces non working configuration Nov 19, 2024
@LeeAdcock
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p1
Projects
None yet
Development

No branches or pull requests

4 participants