-2

ERROR TypeError: file_system__WEBPACK_IMPORTED_MODULE_3__.readFileSync is not a function arg1:TypeError: file_system__WEBPACK_IMPORTED_MODULE_3__.readFileSync is not a function {stack: 'TypeError: file_system__WEBPACK_IMPORTED_MODU…(https://localhost:4200/polyfills.js:9764:30)', message: 'file_system__WEBPACK_IMPORTED_MODULE_3__.readFileSync is not a function'} message:'file_system__WEBPACK_IMPORTED_MODULE_3__.readFileSync is not a function'

When trying to load a ca certificate in Angular 11:

import * as fs from 'file-system';
const httpOptions = 
            {
                headers: new HttpHeaders({'Content-Type': 'application/json'}),
                ca: [fs.readFileSync(['cert.pem', 'key.pem'])],
                rejectUnauthorized: false
            };

The intention is to solve DEPTH_ZERO_SELF_SIGNED_CERT. A browser is supposed not be allowed to access local file system for security reason, but this ca Option sounds like feasible.

Jeb50
  • 6,272
  • 6
  • 49
  • 87
  • Why not `import {readFileSync} from "fs"` instead of using the `file-system` module, which hasn't be updated in 5 years and has a typo in the first sentence of the README. – Dmitry Minkovsky Jun 30 '21 at 00:11
  • You can't access the file system from a webpage... Is this for an electron app? – Samathingamajig Jun 30 '21 at 00:12
  • @Samathingamajig that's also a good question. I assumed this was the backend. – Dmitry Minkovsky Jun 30 '21 at 00:12
  • Well they're using webpack, and you never used webpack on the backend. Webpack just bundles files for the web (converting from `require()` and `import`/`export` into one or a few js files) – Samathingamajig Jun 30 '21 at 00:13
  • @Samathingamajig yes that's a good call – Dmitry Minkovsky Jun 30 '21 at 00:17
  • @Samathingamajig Agree as browser should be a sandbox. What I'm trying to solve is **DEPTH_ZERO_SELF_SIGNED_CERT** but [this](https://levelup.gitconnected.com/how-to-resolve-certificate-errors-in-nodejs-app-involving-ssl-calls-781ce48daded) `ca Option` sounds like feasible. – Jeb50 Jun 30 '21 at 03:06
  • @DmitryMinkovsky What I'm trying to solve is **DEPTH_ZERO_SELF_SIGNED_CERT** but [this](https://levelup.gitconnected.com/how-to-resolve-certificate-errors-in-nodejs-app-involving-ssl-calls-781ce48daded) `ca Option` sounds like feasible. – Jeb50 Jun 30 '21 at 03:07

1 Answers1

0

I'm able to solve this hassle caused by other such as front-end not sending in cookie in SSL, localhost. Please see my answer at Angular Not Sending Cookie

Jeb50
  • 6,272
  • 6
  • 49
  • 87