typescript - npm run build უშვებს შეცდომას Vue 3 პროექტზე, რომელიც იყენებს vite


მე მაქვს უცნაური შეცდომა, როდესაც ვცდილობ გავაკეთო npm run build Vue 3 პროექტზე. იგი ვერ ხერხდება შემდეგით:

[vite:esbuild] Cannot read properties of undefined (reading 'endsWith')
file: /home/simon/vue3/birch-farm/src/main.ts
error during build:
TypeError: Cannot read properties of undefined (reading 'endsWith')
    at file:///home/simon/vue3/birch-farm/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:13301:30

ფაილსა და ხაზში ღრმად შესვლის შემდეგ, ვხედავ, რომ პრობლემას შემდეგი კოდი იწვევს, მაგრამ ვერ ვხვდები, რას შემიძლია გავაკეთო ან სცადო:

function resolveReferencedTSConfigFiles(result) {
  const dir = require$$0$4.dirname(result.tsconfigFile);
  return result.tsconfig.references.map((ref) => {
    const refPath = ref.path.endsWith(".json") ? ref.path : require$$0$4.join(ref.path, "tsconfig.json");
    return resolve2posix(dir, refPath);
  });
}

ჩემი ts.config ფაილი შემდეგია:

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.node.json"
    },
    {
      "path": "./tsconfig.app.json"
    },
    {
      "compilerOptions": {
        "target": "es5",
        "module": "esnext",
        "types": ["node"]
      }
    }    
  ]
}

პასუხი #1

თუ შეამოწმებთ თქვენს "references" მასივის მესამე ობიექტს, რომელიც არის

{
      "compilerOptions": {
        "target": "es5",
        "module": "esnext",
        "types": ["node"]
      }
    }  

ამაში path გასაღები არ არსებობს და ეს ქმნის პრობლემას, რის კარანტინსაც შეგიძლიათ ცოტა შემოწმება დაამატოთ, თუ path არსებობს ამ გასაღებზე, მაშინ გააგრძელეთ პროცესი, წინააღმდეგ შემთხვევაში არაფერი არ გააკეთოთ. ასევე შეგვიძლია გამოვიყენოთ filter ფუნქცია.

function resolveReferencedTSConfigFiles(result) {
  const dir = require$$0$4.dirname(result.tsconfigFile);
  return result.tsconfig.references.map((ref) => {
    const refPath = ref.path.endsWith(".json") ? ref.path : require$$0$4.join(ref.path, "tsconfig.json");
    return resolve2posix(dir, refPath);
  });
}

გააკეთე ამის შეცვლა

function resolveReferencedTSConfigFiles(result) {
  const dir = require$$0$4.dirname(result.tsconfigFile);
  return result.tsconfig.references.filter((ref)=>ref.path!=undefined).map((ref) => {
    const refPath = ref.path.endsWith(".json") ? ref.path : require$$0$4.join(ref.path, "tsconfig.json");
    return resolve2posix(dir, refPath);
  });
}