How can I solve the problem with module 'os' and 'fs' using npm in Laravel 8?
Asked Answered
S

2

0

Suddenly I received the following error:

app.js:28823 Uncaught Error: Cannot find module 'os'
at webpackMissingModule (app.js:28823)
at Object../node_modules/laravel-mix/src/File.js (app.js:28823)
at __webpack_require__ (app.js:79613)
at Object../resources/js/app.js (app.js:6700)
at __webpack_require__ (app.js:79613)
at app.js:79751
at Function.__webpack_require__.O (app.js:79650)
at app.js:79753
at app.js:79755

I tried deleting the node_module folder and the package-lock.json file, and run npm install, to no avail.

When I launch npm run dev I get the following error:

Error: Can't resolve 'os' in 'C:\...\node_modules\clean-css\lib\options'" -t "Laravel Mix"

UPDATE: I run npm install --save os and this problem was solved. But another one arose! Error: Can't resolve 'fs' and this one doesn't resolve with npm install --save fs

NPM version: 7.18.1

Scruggs answered 18/6, 2021 at 8:50 Comment(0)
S
1

SOLVED: I don't know how in the top of resources\js\app.js file appeared this line:

const { exists } = require("laravel-mix/src/File");

I just deleted it and npm run dev didn't give any more errors. I hope this answer will help someone else.

Scruggs answered 18/6, 2021 at 12:38 Comment(1)
thanks today I face this exact same problemHiramhirasuna
F
0

This all happens when you auto-import the modules using any extension.

Solution: delete the package-lock.json file and run: npm i

it works for me.

Another solution is to remove the import { exists } from 'laravel-mix/src/File' from the react component first line and it works.

Forgetful answered 22/12, 2022 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.