Angular 8 - Module not found: Error: Can't resolve 'fs' in

Philip

When I try to use

import { readFileSync } from 'fs';

I get the error

Module not found: Error: Can't resolve 'fs'

In fact, when I use readFileSync in my program in VS even the intellisense works fine, but when I run ng serve it comes up with a compiler error.

I've spent hours looking at other SO posts and searching the internet. Nothing has worked. For example, have tried setting "types": ["node"] where previously it was empty. Have tried using a strange /// syntax for importing, but that didn't work either.

I've also tried strange syntax like import { fs } from '@types/node';.

I'm using fs for the following socket.io call:

this.socket = io('https://12.123.1245:1234', { ca: readFileSync('./assets/cert.pem'), rejectUnauthorized: false });
Thomas

fs is a nodeJs only module. When you run "ng serve" your app will be compiled and run in your browser, so you can not use this mode. To read from a file without user action ( select file ) is not possible for security reason on your browser

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Module not found: Error: Can't resolve 'fs'

Module not found Error : Can't resolve './ ' in Angular8

NUXT: Module not found: Error: Can't resolve 'fs'

Module not found: Error: Can't resolve 'fs' react js

Update to Angular v6 - Module not found: Error: Can't resolve 'fs'

Angular 2 - Module not found: Error: Can't resolve '@angular/material'

Error: Module not found: Error: Can't resolve '@angular/cdk/scrolling'

How to resolve the "Module not found: Error: Can't resolve 'fs'" in nuxt.js?

Module not found: Error: Can't resolve '@angular/core'

Angular 6 setTimeout Module not found: Error: Can't resolve 'timers'

Module not found: Error: Can't resolve '@angular/animations'

Angular 2: Module not found: Error: Can't resolve

Angular 6 - Module not found: Error: Can't resolve 'http' in

Module not found: Error: Can't resolve 'module

With next.js, why did I suddenly start seeing Module not found: Error: Can't resolve 'fs'?

Module not found: Error: Can't resolve 'fs' when trying to use a NodeJS library

Module not found: Error: Can't resolve 'fs' in 'W:\React\bunker\node_modules\send'

Module not found: Can't resolve 'fs' - Calling function

Module not found: Can't resolve 'fs' in Next.js application

Next.js middleware Module not found: Can't resolve 'fs'

Module not found: Error: Cannot resolve module 'fs'

Module not found: Error: Can't resolve 'uuid' in

Module not found: Error: Can't resolve 'hammerjs'

Module not found: Error: Can't resolve './templates'

Module not found: Error: Can't resolve 'util'

Module not found: Error: Can't resolve './components'

Module not found: Error: Can't resolve 'ReactDOM'

Module not found: Error: Can't resolve 'avoriaz'

Module not found: Error: Can't resolve 'dropzone'