boonya / rtsp-video-recorder

Provides an API to record RTSP video stream to filesystem.
https://www.npmjs.com/package/rtsp-video-recorder
MIT License
33 stars 4 forks source link

Module not found: Error: Can't resolve 'fs' Module Warning (from ./node_modules/source-map-loader/dist/cjs.js): Failed to parse source map from ... #219

Closed KillianLachx closed 2 years ago

KillianLachx commented 2 years ago

Hello,

I'm trying to use this module but I'm having a lot of trouble, I keep getting the same errors. I try to run my node server but I get a bunch of Module not found : 'fs' and 'child_process', and Module Warning : Failed to parse source map from ... .

I searched for those errors on the web and found a lot of different sources for it but I tried a few solutions and it didn't help.

I'm using a React node 16.14.0 server on Windows 10, I have ffmpeg ver. N-105739-g8ef03c2ff1-20220224 installed and in my Path, I can call it from a command line.

Here is the code I'm trying to run :

const recorder = new Recorder('rtsp://@192.168.255.255:1234', 'D:\\filepath\\TO\\project\\backend\\backend-simple\\videoclips', {title: 'cam'});

        recorder.start();

        setTimeout(() => {
            recorder.stop();
            recorder = null;
        }, this.state.seconds_to_rec * 1000);

Can anyone help me ? Do you have any idea what's causing this ?

Thanks a lot !

boonya commented 2 years ago

React? It's not a client side library. It's impossible to execute it on a client side. You need nodejs environment and ffmpeg installed. 'fs' and 'child_process' is a part of Node JS API. There is no such API in a browser environment. Could you please provide some more details about your issue? May be I missed something.

KillianLachx commented 2 years ago

Sorry if including React mislead you, I am trying to use the module for a node.js server, I'm using react to provide an easy to use interface from my browser. I do have ffmpeg installed and I can run it by typing ffmpeg from my command line.

Here is my complete error stack trace running npm start :

Failed to compile.

Module not found: Error: Can't resolve 'fs' in 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\dist\helpers'
assets by path static/ 1.54 MiB
  asset static/js/bundle.js 1.53 MiB [emitted] (name: main) 1 related asset
  asset static/js/node_modules_web-vitals_dist_web-vitals_js.chunk.js 6.93 KiB [emitted] 1 related asset
  asset static/media/logo.6ce24c58023cc2f8fd88fe9d219db6c6.svg 2.57 KiB [emitted] (auxiliary name: main)
asset index.html 1.67 KiB [emitted]
asset asset-manifest.json 546 bytes [emitted]
cached modules 1.42 MiB [cached] 120 modules
runtime modules 31.3 KiB 15 modules

WARNING in ./node_modules/rtsp-video-recorder/dist/error.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\error.ts' file: Error: ENOENT: no such file or directory, open 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\error.ts'
 @ ./node_modules/rtsp-video-recorder/dist/recorder.js 27:16-34
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

WARNING in ./node_modules/rtsp-video-recorder/dist/helpers/directoryExists.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\helpers\directoryExists.ts' file: Error: ENOENT: no such file or directory, open 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\helpers\directoryExists.ts'
 @ ./node_modules/rtsp-video-recorder/dist/validators.js 14:42-78
 @ ./node_modules/rtsp-video-recorder/dist/recorder.js 42:21-44
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

WARNING in ./node_modules/rtsp-video-recorder/dist/helpers/segmentTime.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\helpers\segmentTime.ts' file: Error: ENOENT: no such file or directory, open 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\helpers\segmentTime.ts'
 @ ./node_modules/rtsp-video-recorder/dist/recorder.js 48:38-70
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

WARNING in ./node_modules/rtsp-video-recorder/dist/helpers/sizeThreshold.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\helpers\sizeThreshold.ts' file: Error: ENOENT: no such file or directory, open 
'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\helpers\sizeThreshold.ts'
 @ ./node_modules/rtsp-video-recorder/dist/recorder.js 46:40-74
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

WARNING in ./node_modules/rtsp-video-recorder/dist/helpers/space.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\helpers\space.ts' file: Error: ENOENT: no such file or directory, open 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\helpers\space.ts'
 @ ./node_modules/rtsp-video-recorder/dist/recorder.js 44:32-58
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

WARNING in ./node_modules/rtsp-video-recorder/dist/recorder.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\recorder.ts' file: Error: ENOENT: no such file or directory, open 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\recorder.ts'
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

WARNING in ./node_modules/rtsp-video-recorder/dist/types.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\types.ts' file: Error: ENOENT: no such file or directory, open 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\types.ts'
 @ ./node_modules/rtsp-video-recorder/dist/recorder.js 18:16-34
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

WARNING in ./node_modules/rtsp-video-recorder/dist/validators.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\validators.ts' file: Error: ENOENT: no such file or directory, open 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\src\validators.ts'
 @ ./node_modules/rtsp-video-recorder/dist/recorder.js 42:21-44
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

8 warnings have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

ERROR in ./node_modules/rtsp-video-recorder/dist/helpers/directoryExists.js 13:29-42
Module not found: Error: Can't resolve 'fs' in 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\dist\helpers'
 @ ./node_modules/rtsp-video-recorder/dist/validators.js 14:42-78
 @ ./node_modules/rtsp-video-recorder/dist/recorder.js 42:21-44
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

ERROR in ./node_modules/rtsp-video-recorder/dist/helpers/space.js 13:29-42
Module not found: Error: Can't resolve 'fs' in 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\dist\helpers'
 @ ./node_modules/rtsp-video-recorder/dist/recorder.js 44:32-58
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

ERROR in ./node_modules/rtsp-video-recorder/dist/recorder.js 14:24-48
Module not found: Error: Can't resolve 'child_process' in 'D:\Cours\TEMI\plateforme\backend\backend-simple\node_modules\rtsp-video-recorder\dist'
 @ ./src/components/RecordForm.js 5:0-63 43:27-35
 @ ./src/App.js 5:0-49 35:32-42
 @ ./src/index.js 7:0-24 11:33-36

3 errors have detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

webpack 5.69.1 compiled with 3 errors and 8 warnings in 26315 ms

Here is my package.json file :

{
  "name": "backend-simple",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.2",
    "@testing-library/react": "^12.1.3",
    "@testing-library/user-event": "^13.5.0",
    "fs": "^0.0.1-security",
    "node-rtsp-recorder": "^1.0.3",
    "path": "^0.12.7",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "5.0.0",
    "rtsp-video-recorder": "^2.0.3",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "browser": {
    "fs": false,
    "path": false,
    "os": false
  }
}
KillianLachx commented 2 years ago

Ok, after trying out a few different modules, turns out I have similar errors on almost all of them, so the probleme probably isn't from your package. It seems like my modules can't find the base node ones. Do you know what might be the issue ? I have been looking around for a while and I can't manage to fix it

boonya commented 2 years ago

Again, from your package.json file I see you are trying to use this within a browser environment. It really seems like Create React App. It doesn't matter whether you have nodejs & ffmpeg installed in this case or not. There is no proper fs API in a browser. You have to implement simple server side for that. So, your react application will interact with your backend to control ffmpeg process through this library API.

boonya commented 2 years ago

For that needs you can use meteor js for example. Here you can find an example of how to use meteor, react, ffmpeg and the library. I have already started to work on this year ago or earlier. But do not have enough time to finish it. But it should work already.

KillianLachx commented 2 years ago

Ho, I see... Yes it is a create react app, I'm new to this, I misunderstood what really happens server and client side.

Thanks for the clarifications ! I will look up another way to do this