json - Hur får jag min VS Code-plugin att bygga när jag får felet 'Kan inte lösa "fs" eller "child_process"'?


Raden som initialiserar ett SimpleGit-objekt const git: SimpleGit=simpleGit().clean(CleanOptions.FORCE); orsakar ett problem med byggandet av mitt projekt som resulterar i felet "Kan inte lösa 'fs' i /node_modules/@kwsites/file-exists/dist/src"... "Fältet 'browser' innehåller inte en giltig alias-konfiguration" (och sedan samma fel med 'child_process' istället för 'fs').

Jag importerar simple-git med den sista metoden som listas under 'Usage' härifrån, och har även försökt använda de andra 2 metoderna, som alla leder till detta fel.

// Option 3
import { simpleGit, SimpleGit, CleanOptions } from 'simple-git';
const git: SimpleGit = simpleGit().clean(CleanOptions.FORCE);

Jag följde ursprungligen denna guide för att sätta upp VS Code-pluginet som använder esbuild. Efter att ha spenderat en dag på att försöka lista ut detta, bytte jag till denna version som använder WebPack istället (eftersom det verkar finnas mer hjälp online med WebPack), men kunde fortfarande inte hitta en fungerande lösning.

Det nuvarande felet när jag bygger är:

ERROR in ./node_modules/@kwsites/file-exists/dist/src/index.js 6:13-26
Module not found: Error: Can't resolve 'fs' in '/filepath/hello-world/node_modules/@kwsites/file-exists/dist/src'
resolve 'fs' in '/filepath/hello-world/node_modules/@kwsites/file-exists/dist/src'
  Parsed request is a module
  using description file: /filepath/hello-world/node_modules/@kwsites/file-exists/package.json (relative path: ./dist/src)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /filepath/hello-world/node_modules/@kwsites/file-exists/dist/src/node_modules doesn't exist or is not a directory
      /filepath/hello-world/node_modules/@kwsites/file-exists/dist/node_modules doesn't exist or is not a directory
      /filepath/hello-world/node_modules/@kwsites/file-exists/node_modules doesn't exist or is not a directory
      /filepath/hello-world/node_modules/@kwsites/node_modules doesn't exist or is not a directory
      /filepath/hello-world/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in /filepath/hello-world/node_modules
        single file module
          using description file: /filepath/hello-world/package.json (relative path: ./node_modules/fs)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /filepath/hello-world/node_modules/fs doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /filepath/hello-world/node_modules/fs.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /filepath/hello-world/node_modules/fs.js doesn't exist
 @ ./node_modules/@kwsites/file-exists/dist/index.js 6:9-25
 @ ./node_modules/simple-git/dist/cjs/index.js 261:25-56
 @ ./src/webview/main.ts 14:21-42

webpack 5.75.0 compiled with 2 errors in 21770 ms
    [webpack-cli] Compiler is watching files for updates...

Det avsedda resultatet är en lyckad byggnation.

Här är de lösningar jag har försökt (och som inte fungerade): Modul hittades inte: Fel: Kan inte lösa 'fs' i Kan inte hitta modul 'fs'

Electron: Modul hittades inte: Fel: Kan inte lösa 'fs' Kräv nodejs "child_process" med TypeScript, SystemJS och Electron Här är en lösning jag inte provade (för att jag inte förstod vad som sades/fanns inte tillräckligt med information): https://github.com/NativeScript/nativescript-dev-appium/issues/223#issuecomment-498569080

Och en lista över platser jag har tittat på som inte hade ett bra svar för min ansökan: NodeJS - Kan inte hitta modul i child_process Kan inte hitta namnet 'module'

Efter att ha läst Hur man fixar kan inte hitta modul 'fs' och Ouppfångat fel: Kan inte hitta modul "fs", verkar det som om det kan finnas ett problem mellan min förståelse av klient-sida och server-sida utveckling (jag är inte helt säker på om det är min användning av simple-git i en WebView-applikation som orsakar dessa problem).

Om någon har någon insikt eller ytterligare kommentarer eller lösningar som jag inte har provat skulle jag verkligen uppskatta din hjälp. Tack!

Redigera: Jag försöker också ändra filer, och metoden att importera filsystemet som en variabel resulterar också i samma felmeddelande: var fs=require('fs');