The line that initializes a SimpleGit object const git: SimpleGit = simpleGit().clean(CleanOptions.FORCE);
causes an issue with the build of my project that results in the error "Can't resolve 'fs' in /node_modules/@kwsites/file-exists/dist/src"... "Field 'browser' doesn't contain a valid alias configuration" (and then the same error with 'child_process' instead of 'fs').
I am importing simple-git using the last method listed under 'Usage' from here, and also tried using the other 2 methods, all of which lead to this error.
// Option 3
import { simpleGit, SimpleGit, CleanOptions } from 'simple-git';
const git: SimpleGit = simpleGit().clean(CleanOptions.FORCE);
I originally followed this guide to set up the VS Code Plugin which uses esbuild. After spending a day trying to figure this out, I switched to this version that uses WebPack instead (since there seems to be more help online with WebPack), but was still unable to find a working solution.
The current error when I build is:
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...
The intended outcome is a successful build.
Here are the solutions I have tried (and did not work): Module not found: Error: Can't resolve 'fs' in Cannot find module 'fs'
Electron: Module not found: Error: Can't resolve 'fs' Require nodejs "child_process" with TypeScript, SystemJS and Electron Here is a solution I did not try (because I didn't understand what was said/wasn't enough info): https://github.com/NativeScript/nativescript-dev-appium/issues/223#issuecomment-498569080
And a list of places I have looked that did not have a good answer for my application: NodeJS - Cannot find module in child_process Cannot find name 'module'
After reading How to fix cannot find module 'fs' and Uncaught Error: Cannot find module "fs", it seems like there may be an issue between my understanding of client-side and server-side development (I am not entirely sure if it's my use of simple-git in a WebView application causing these issues).
If anyone has any insight, or additional comments solutions that I haven't tried I would really appreciate your help. Thank you!
Edit: I also am trying to modify files, and the method of importing file system as a variable also results in the same error message:
var fs = require('fs');