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

semver-utils isn't exported #1461

Open
1 task done
regseb opened this issue Oct 2, 2024 · 9 comments
Open
1 task done

semver-utils isn't exported #1461

regseb opened this issue Oct 2, 2024 · 9 comments
Labels

Comments

@regseb
Copy link
Contributor

regseb commented Oct 2, 2024

semver-utils is imported in build/index.d.ts. But the library semver-utils isn't in the package.json dependencies.


Steps to Reproduce

Files:

  • package.json

    {
        "name": "testcase",
        "version": "1.0.0",
        "type": "module",
        "dependencies": {
            "npm-check-updates": "17.1.3",
            "typescript": "5.6.2"
        }
    }
  • index.ts

    import ncu from "npm-check-updates";
    
    console.log(await ncu.run());

Steps:

  1. npm install
  2. npx tsc --module nodenext index.ts

Current Behavior

node_modules/npm-check-updates/build/index.d.ts:1:24 - error TS2307: Cannot find module 'semver-utils' or its corresponding type declarations.

1 import { SemVer } from 'semver-utils';
                         ~~~~~~~~~~~~~~


Found 1 error in node_modules/npm-check-updates/build/index.d.ts:1

Expected Behavior

No error.

@raineorshine
Copy link
Owner

Hi, thanks for reporting.

semver-utils is included in the package.json, but maybe Rollup is not bundling it properly. Do you know how to force Rollup to include a library?

@regseb
Copy link
Contributor Author

regseb commented Oct 2, 2024

semver-utils is in the "devDependencies" that aren't published. It should be put in "dependencies".

@raineorshine
Copy link
Owner

Vite uses Rollup to automatically tree shake the devDependencies and bundle them for production.

https://github.com/raineorshine/npm-check-updates/blob/main/vite.config.mts

@raineorshine
Copy link
Owner

I'm sure it's just a matter of adding it to the Vite config. I'll play around with it next chance I get :).

@regseb
Copy link
Contributor Author

regseb commented Oct 4, 2024

The problem occurred with version 17.0.0. There is no error with version 16.14.20.

I think Vite / Rollup don't handle bundles of .d.ts files very well. If the semver-utils source code is bundled in the index.js file. The types of semver-utils should also be bundled in the index.d.ts file.

@raineorshine
Copy link
Owner

raineorshine commented Oct 5, 2024

I have added @types/semver-utils to the tsconfig paths. Can you try it with npm install [email protected]?

diff --git a/tsconfig.json b/tsconfig.json
index 0d900ee3..7ce5b455 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -15,6 +15,7 @@
     "noImplicitAny": true,
     "paths": {
       "libnpmconfig": ["./src/types/libnpmconfig"],
+      "@types/semver-utils": ["./node_modules/@types/semver-utils"],
       "prompts-ncu": ["./src/types/prompts-ncu"]
     },
     "resolveJsonModule": true,

Reference: https://github.com/qmhc/vite-plugin-dts#type-errors-that-are-unable-to-infer-types-from-packages-in-node_modules

@regseb
Copy link
Contributor Author

regseb commented Oct 5, 2024

I still have the same error. The import of semver-utils is still in the index.d.ts file.

I think your configuration change doesn't fix the problem, because you define a path for @types/semver-utils, but it's semver-utils that gets imported.

@raineorshine
Copy link
Owner

Hmmm okay. I'll try to think of something else 🤔

@raineorshine
Copy link
Owner

I have limited time right now, so it would be great if somebody could jump in and investigate this further! 🙏

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

No branches or pull requests

2 participants