ref Node esBuild suddenly failing with FSLegacyMainResolve problem
Question
I have a Node project that builds fine locally, and has historically built with no problems on the GitLab CI/CD server. However, suddenly, the pipeline build fails on the server with no changes to the code. I even opened several branches for past commits that previously built fine, and they also fail on the server.
I'm mostly trying to understand what this error "means":
const resolvedOption = FSLegacyMainResolve(packageJsonUrlString, packageConfig.main, baseStringified);
^
TypeError: The URL must be of scheme file: <etc...>
I have to assume something changed in the build environment, it's not able to pull down a package suddenly, or similar, but there's nothing really specific about what the problem might be. I'm looking for pointers about why this is occurring, and possibly how to troubleshoot.
Relevant error from the log on the build server is:
$ npm install
added 362 packages, and audited 363 packages in 17s
47 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
$ echo "Compile complete."
Compile complete.
$ npm run build
> my-project@1.0.0 build
> tsc -skipLibCheck && node esbuild.config.mjs production && npm pack
node:internal/modules/esm/resolve:205
const resolvedOption = FSLegacyMainResolve(packageJsonUrlString, packageConfig.main, baseStringified);
^
TypeError: The URL must be of scheme file:
at legacyMainResolve (node:internal/modules/esm/resolve:205:26)
at packageResolve (node:internal/modules/esm/resolve:831:14)
at moduleResolve (node:internal/modules/esm/resolve:901:20)
at defaultResolve (node:internal/modules/esm/resolve:1121:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
at link (node:internal/modules/esm/module_job:84:36) {
code: 'ERR_INVALID_URL_SCHEME'
}
Node.js v20.10.0
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1
Again, this runs just fine locally, same version of Node.js, etc. I've cleared local npm cache, deleted node_modules, etc, all in an attempt to potentially replicate the server-side state, but still everything works fine locally.
Answer
I was facing the same issue, but this worked for me
- Delete the node_modules directory:
rm -rf node_modules
- Install dependencies with the --legacy-peer-deps flag:
npm install --legacy-peer-deps