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

@napi-rs/cli@2.15.2 generate duplicate definitions in .d.ts #1541

Closed
xiaopengli89 opened this issue Mar 24, 2023 · 13 comments
Closed

@napi-rs/cli@2.15.2 generate duplicate definitions in .d.ts #1541

xiaopengli89 opened this issue Mar 24, 2023 · 13 comments

Comments

@xiaopengli89
Copy link
Contributor

No description provided.

@Brooooooklyn
Copy link
Sponsor Member

Try to upgrade napi-derive

@xiaopengli89
Copy link
Contributor Author

Thanks!

@xiaopengli89
Copy link
Contributor Author

The definition still be repeated.

napi-cli: 2.15.2
napi: 2.12.1
napi-derive: 2.12.2
napi-build: 2.0.1

@xiaopengli89 xiaopengli89 reopened this Mar 29, 2023
@miniben-90
Copy link

miniben-90 commented Apr 1, 2023

Hi,
I have same issue with duplication of .d.ts and .js code only in windows 11 (the code is duplicated 3 times for .d.ts and 6 times for index.js)

  • rustc: 1.68.2 (9eb3afe9e 2023-03-27)
  • cargo: 1.68.2 (6feb7c9cf 2023-03-26)
  • NodeJS: v18.12.1
  • @napi-rs/cli: 2.15.2
  • napi: 2.12.0
  • napi-derive: 2.12.2

I'm using #[cfg(target_os = "...")] in my lib.rs to handle for macos, linux and windows:

#[cfg(target_os = "windows")]
mod win32;
#[cfg(target_os = "windows")]
use win32::init_platform_api;

#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
use linux::init_platform_api;

#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
use macos::init_platform_api;

@Brooooooklyn
Copy link
Sponsor Member

@miniben-90 Because of the limitations of the Rust macro, your case napi-derive cannot currently handle... You may need to add #[napi(skip_typescript)] under 2 of these platforms

@xiaopengli89
Copy link
Contributor Author

I don't have conditional compilation code, it works fine with 2.14.8.

@miniben-90
Copy link

@miniben-90 Because of the limitations of the Rust macro, your case napi-derive cannot currently handle... You may need to add #[napi(skip_typescript)] under 2 of these platforms

Thanks for your answer, but nothing change after adding skip_typescript... I switch back to 2.14.8 for @napi-rs/cli.

@Brooooooklyn Brooooooklyn reopened this Apr 6, 2023
@Brooooooklyn
Copy link
Sponsor Member

@xiaopengli89 do you have a minimal reproducible repo?

@xiaopengli89
Copy link
Contributor Author

I removed the rust binding method, but it still generates the previous code, and it looks like @napi-rs/cli@2.15.2 is caching the previous code. This problem does not occur when creating a new project.

@forehalo
Copy link
Member

forehalo commented Apr 7, 2023

@xiaopengli89

I removed the rust binding method, but it still generates the previous code, and it looks like @napi-rs/cli@2.15.2 is caching the previous code. This problem does not occur when creating a new project.

We do cache the previous typedef because users may delete *.d.ts generated previously but leave rust code untouched, in which case, cargo will not compile the rust code due to strong cache and we finally get an empty *.d.ts if we don't cache the previous one.

After removing rust binding method, you should compile your crate with cargo build directly instead of using napi build because it's no longer node binding lib and all the pre-build and post-build stuffs napi cli do are useless.

@art049
Copy link

art049 commented Apr 28, 2023

I don't have conditional compilation code, it works fine with 2.14.8.

I had the same behavior with 2.15.2 and can confirm reverting to 2.14.8 fixed the issue.
I don't really understand what's going on with the cache so providing a reproduction is difficult.

@ceifa
Copy link
Contributor

ceifa commented May 7, 2023

I don't have conditional compilation code, it works fine with 2.14.8.

The problem started on 2.15.1, so it's safe to keep on 2.15.0 too. #1531

@CyriacBr
Copy link

CyriacBr commented Sep 9, 2023

This issue was closed as completed, but even with the latest version of @napi/cli, I got duplicated index.d.ts and index.js files.
Reverting to 2.14.8 fixed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants