node.js - node_modules/minimatch/dist/cjs/index"' אין חבר מיוצא בשם 'IMinimatch'. האם התכוונת ל- 'Minimatch'?


יש לי את rimraf כתלות פיתוח (v5.0.0). כשאני מנסה להריץ סקריפט שמשתמש ב-rimraf הוא נותן לי את השגיאה הזו:

node_modules/@types/glob/index.d.ts:29:42 - error TS2694: Namespace '".../node_modules/minimatch/dist/cjs/index"' has no exported member 'IOptions'.
29     interface IOptions extends minimatch.IOptions {
                                            ~~~~~~~~

node_modules/@types/glob/index.d.ts:74:30 - error TS2724: '"...node_modules/minimatch/dist/cjs/index"' has no exported member named 'IMinimatch'. Did you mean 'Minimatch'?

74         minimatch: minimatch.IMinimatch;
                                ~~~~~~~~~~


Found 2 errors in the same file, starting at: node_modules/@types/glob/index.d.ts:29

הסרתי ידנית את התיקייה node_modules/@types/glob והשגיאה נעלמה, rimraf עובד בצורה מושלמת. הבעיה היא שאין לי את glob או minimatch או את הסוגים שלהם כתלויות בפרויקט שלי, אז אני לא מסוגל להסיר את התלות כדי לפתור את הבעיה.

אלה התלויות שיש לי בקובץ package.json שלי:

"devDependencies": {
    "@open-wc/building-rollup": "2.0.1",
    "@open-wc/eslint-config": "7.0.0",
    "@open-wc/testing": "3.1.3",
    "@rollup/plugin-replace": "4.0.0",
    "@typescript-eslint/eslint-plugin": "5.20.0",
    "@typescript-eslint/parser": "5.20.0",
    "@web/dev-server": "0.1.30",
    "@web/test-runner": "0.13.27",
    "@web/test-runner-puppeteer": "0.10.5",
    "concurrently": "7.1.0",
    "deepmerge": "4.2.2",
    "eslint": "8.13.0",
    "eslint-config-prettier": "8.5.0",
    "husky": "7.0.4",
    "lint-staged": "12.4.0",
    "prettier": "2.6.2",
    "rimraf": "5.0.0",
    "rollup": "2.70.2",
    "rollup-plugin-copy": "3.4.0",
    "tslib": "2.3.1",
    "typescript": "4.6.3"
  }

אני לא יודע אם זה רק rimraf שגורם לבעיה, או שזה יכול להיות אחר.

מעריך את התשובות! :)

תשובה #1

פתרתי בעיה דומה פשוט על ידי הכרחה לדרוס את החבילות glob ו-minimatch. אולי זו לא הפתרון הנכון, אבל ראיתי הרבה חבילות מקוננות שמשתמשות בגרסאות שונות של minimatch ו-glob, אז הניסיון הראשון שלי היה להשתמש בחבילות העדכניות ביותר.

צעדים

1- הוספתי בסוף package.json את הבא

 ... 
 "overrides": {
    "minimatch": "5.1.2",
    "glob": "8.1.0"
  },
 ...

2- אחרי ההוספה ל-package.json, כל מה שאני צריך זה לבצע prune:

npm prune

אופציונלי: במקרה שזה לא עובד, נסו להסיר את node_modules ואת package-lock.json

rm -rf node_modules; rm package-lock.json

ולהתקין שוב את כל המודולים/חבילות

npm התקן

כאן הדוגמה המלאה אם אתה רוצה לראות איפה להוסיף בתוך הקובץ package.json שלך:

{
  "name": "foo",
  "version": "0.0.0",
  "dependencies": {
    "express": "expressjs/express",
    "mocha": "mochajs/mocha#4727d357ea",
    "module": "user/repo#feature/branch"
  },
  "overrides": {
    "minimatch": "5.1.2",
    "glob": "8.1.0"
  }
}

תיעוד NPM

תשובה #2

אם הייתי צריך לנחש, נראה שאחת התלויות שלך נתקלת בבעיה עם הגרסה.

אני הייתי מנסה למחוק את package.json ולהתקין מחדש.

אתה יכול גם לקרוא עוד על הבעיה הספציפית שלך כאן: https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/63967

עריכה: לאחר קצת מחקר נוסף, גיליתי שחבילות @types עבור התלויות הספציפיות האלה עשויות לגרום לבעיה. נסה להסירן.