How can I solve the problem with module 'os' and 'fs' using npm in Laravel 8? - laravel

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

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.

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.

Related

1 WARNING in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)

How can I solve this warning when creating laravel project?
1 WARNING in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)
Steps to replicate:
composer create-project --prefer-dist laravel/laravel example
cd example
composer require laravel/ui
php artisan ui vue --auth
npm install vue#next vue-router#next vue-loader#next
npm install
npm run dev
EDIT
From this solution, add these lines to webpack.mix.js
mix.webpackConfig({
stats: {
children: true,
},
});
The above solution creates another warning:
WARNING in ./resources/sass/app.scss (./node_modules/css-loader/dist/cjs.js??clonedRuleSet-6.use1!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-6.use[2]!./node_modules/resolve-url-loader/index.js??clonedRuleSet-6.use[3]!./node_modules/sass-loader/dist/cjs.js??clonedRuleSet-6.use[4]!./resources/sass/app.scss)
Module Warning (from ./node_modules/postcss-loader/dist/cjs.js):
Warning
(2423:3) autoprefixer: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.
Child mini-css-extract-plugin C:\xampp\htdocs\lva\node_modules\css-loader\dist\cjs.js??clonedRuleSet-6.use1!C:\xampp\htdocs\lva\node_modules\postcss-loader\dist\cjs.js??clonedRuleSet-6.use[2]!C:\xampp\htdocs\lva\node_modules\resolve-url-loader\index.js??clonedRuleSet-6.use[3]!C:\xampp\htdocs\lva\node_modules\sass-loader\dist\cjs.js??clonedRuleSet-6.use[4]!C:\xampp\htdocs\lva\resources\sass\app.scss compiled with 1 warning
webpack compiled with 1 warning
How can I solve this?
The color-adjust shorthand is currently deprecated and it depends on the autoprefixer#10.4.6 (source).
I was able to fix this by reverting the autoprefixer package as well as #Benno to version 10.4.5. Run this:
npm install autoprefixer#10.4.5 --save-exact
You probably updated your npm packages. I was able to fix this by reverting the autoprefixer package to version 10.4.5 in the package-lock.json.
when you have problem with autoprefixer maybe because your version autoprefixer. you can add version autoprefixer based problem this version autoprefixer . i have problem on "print-color-adjust" and i add code on my package.json for change my autoprefixer become version "10.4.5"
when you use npm
"overrides": {
"autoprefixer": "10.4.5"
},
Or, when you use yarn
"resolutions": {
"autoprefixer": "10.4.5"
},
Don't forget to delete your package-lock and node_modules , then npm install again.
it work for me (react-bootstrap.v.5)
If you don't want to add additional packages to solve this error, then try this:
Capitalize all the files and Directory name in your components folder
Or you can run this command to install a package if the above solution doesn't work.
npm install autoprefixer#10.4.5 --save-exact
I'm using React with InertiaJS and Laravel as backend, this solution worked in my case.
Thanks
I have the same problem, whenever I hit save an annoying pop-up of error code comes. The simple solution is to add the following code to your webpack.mixjs file :
mix.webpackConfig({
stats: {
children: true,
},});
stop the npm run watch
add a package autoprefixer, add below in terminal:
npm install autoprefixer#10.4.5 --save-exact
run npm run watch and it will not give the error again.
I solved this issue within Laravel by changing the file ./node_modules/bootstrap/scss/forms/_form-check.scss
Line 28 part of the .form-check-input style
change color-adjust: exact; // Keep themed appearance for print
to print-color-adjust: exact; // Keep themed appearance for print

NPM broken TypeError: Cannot read property 'loaded' of undefined

NPM has been installed by the Azure DevOps agent install on my mac os Mojave v10.14.6. I can access the npm but any commadn gives tha same error. this is the only command that work
sudo npm --version =6.12.0
sudo npm -p process.platform = darwin
this is the same error message I get for any other command:
Error: EISDIR: illegal operation on a directory, read TypeError:
Cannot read property 'loaded' of undefined
at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:97:27)
at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:78:20
at cb (/usr/local/lib/node_modules/npm/lib/npm.js:225:22)
at /usr/local/lib/node_modules/npm/lib/npm.js:263:24
at /usr/local/lib/node_modules/npm/lib/config/core.js:81:7
at Array.forEach ()
at /usr/local/lib/node_modules/npm/lib/config/core.js:80:13
at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)
at finalize (/usr/local/lib/node_modules/npm/lib/config/core.js:187:14)
/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:97 var
doExit = npm.config.loaded ? npm.config.get('_exit') : true
I have downloaded the latest version node version from nodejs.org and this has not help.
I believe the problem is that it is missing the .npmrc but i might be wrong.
I ran locate command and here are all the results anything under deb/myagent is azure devops pulled source for building the apps:
Mac-mini:/ sedev$ locate .npmrc
/Applications/Xcode.app/Contents/Developer/usr/share/xcs/xcsd/node_modules/nsp/node_modules/npmconf/test/fixtures/.npmrc
/Applications/Xcode.app/Contents/Developer/usr/share/xcs/xcsd/node_modules/nsp/node_modules/silent-npm-registry-client/node_modules/npm-registry-client/node_modules/npmlog/.npmrc
/Users/sedev/.npmrc
/Users/sedev/myagent/_work/10/s/app.WebUi/wwwroot/bower_components/vaadin-checkbox/.npmrc
/Users/sedev/myagent/_work/10/s/app.WebUi/wwwroot/bower_components/vaadin-control-state-mixin/.npmrc
/Users/sedev/myagent/_work/10/s/app.WebUi/wwwroot/bower_components/vaadin-element-mixin/.npmrc
/Users/sedev/myagent/_work/10/s/app.WebUi/wwwroot/bower_components/vaadin-grid/.npmrc
/Users/sedev/myagent/_work/10/s/app.WebUi/wwwroot/bower_components/vaadin-grid-5.0.0-alpha6/.npmrc
/Users/sedev/myagent/_work/10/s/app.WebUi/wwwroot/bower_components/vaadin-icons/.npmrc
/Users/sedev/myagent/_work/10/s/app.WebUi/wwwroot/bower_components/vaadin-text-field/.npmrc
/Users/sedev/myagent/_work/10/s/app.WebUi/wwwroot/bower_components/vaadin-themable-mixin/.npmrc
Mac-mini:/ sedev$
The answer was the .npmrc was corrupt or something. I had to remove it and it worked
sudo rm /Users/sedev/.npmrc
It Is Possible someTime That Node has crashed.
so solution Is That Uninstall NodeJs and Install it Againg
Install for [ 'browserslist#latest' ] => npm i browserslist#latest

"This dependancy was not found" when i try to import from ckeditor

I try to create a custom plugin. Wheni import Image from '#ckeditor/ckeditor5-image/src/image' i get an error
This dependency was not found:
* -!../../../css-loader/index.js??ref--6-oneOf-3-1!../../../postcss- loader/src/index.js??ref--6-oneOf-3-2!./#ckeditor/ckeditor5-theme- lark/theme/mixins/_rwd.css in ./node_modules/css-loader??ref--6-oneOf-3-
1!./node_modules/postcss-loader/src??ref--6-oneOf-3-
2!./node_modules/#ckeditor/ckeditor5-image/theme/textalternativeform.css
To install it, you can run: npm install --save -!../../../css-
loader/index.js??ref--6-oneOf-3-1!../../../postcss-loader/src/index.js??
ref--6-oneOf-3-2!./#ckeditor/ckeditor5-theme-lark/them
How should i fix it? I've installed this package https://github.com/ckeditor/ckeditor5-theme-lark and there is no effect.
Make sure you have created the vue.config.js file and included the details from
https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/frameworks/vuejs.html
Make sure #ckeditor/ckeditor5-theme-lark is installed
npm install --save #ckeditor/ckeditor5-theme-lark
That should then fix the issue
after modified the vue.config.js make sure you are re-run again your VUE application
npm run dev
or
npm run serve
In my case, I got same error because I did not follow the guide very well. After read it I had to run this:
npm install #ckeditor/ckeditor5-theme-lark
npm install --save #ckeditor/ckeditor5-vue2 #ckeditor/ckeditor5-dev-webpack-plugin #ckeditor/ckeditor5-dev-utils postcss-loader#4 raw-loader#4
For specific modules selected, something like this:
npm install --save #ckeditor/ckeditor5-basic-styles #ckeditor/ckeditor5-editor-classic #ckeditor/ckeditor5-horizontal-line #ckeditor/ckeditor5-alignment #ckeditor/ckeditor5-autosave #ckeditor/ckeditor5-adapter-ckfinder #ckeditor/ckeditor5-essentials #ckeditor/ckeditor5-font #ckeditor/ckeditor5-heading #ckeditor/ckeditor5-image #ckeditor/ckeditor5-indent #ckeditor/ckeditor5-link #ckeditor/ckeditor5-list #ckeditor/ckeditor5-paragraph #ckeditor/ckeditor5-paste-from-office #ckeditor/ckeditor5-remove-format #ckeditor/ckeditor5-typing #ckeditor/ckeditor5-basic-styles
Then, in my case I use VUE 2+ version, so I had to modify the vue.config.js file, accorging the official documentation: https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/frameworks/vuejs-v2.html
Plase check the documentation with your specific framework: https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/frameworks/overview.html

Laravel error when running npm run dev command

When I run npm run dev in the terminal I get the following message:
ERROR in ./resources/js/components/ExampleComponent.vue
Module build failed (from ./node_modules/vue-loader/lib/index.js):
Error: [vue-loader] vue-template-compiler must be installed as a peer dependency, or a compatible compiler implementation must be passed via options.
at loadTemplateCompiler (/portal/node_modules/vue-loader/lib/index.js:21:11)
at Object.module.exports (
(/portal/node_modules/vue-loader/lib/index.js:65:35)
# ./resources/js/app.js 19:35-79
# multi ./resources/js/app.js ./resources/sass/app.scss
Can anyone tell me what this error means and how do I fix it?
I tried to run this command in the terminal, but I am still getting the error.
The command: npm i -D vue-template-compiler
I have also tried to reinstall all of my dependencies, but that didnt work either.

Failed at the # production script. Error running npm run production

I am facing issue while using the following command
npm run production
after execute following command i see following error
ERROR Failed to compile with 5 errors
error in ./resources/assets/sass/app.scss
Module build failed: ModuleBuildError: Module build failed: TypeError: Cannot read property 'map' of undefined
at preparePluginsArray (E:\wamp\www\smm.yasmalik.com\node_modules\svgo\lib\svgo\config.js:64:20)
at module.exports (E:\wamp\www\smm.yasmalik.com\node_modules\svgo\lib\svgo\config.js:32:28)
at new module.exports (E:\wamp\www\smm.yasmalik.com\node_modules\svgo\lib\svgo.js:21:19)
at E:\wamp\www\smm.yasmalik.com\node_modules\postcss-svgo\dist\index.js:95:16
at Object.creator [as postcssSvgo] (E:\wamp\www\smm.yasmalik.com\node_modules\postcss-svgo\node_modules\postcss\lib\postcss.js:150:35)
at E:\wamp\www\smm.yasmalik.com\node_modules\cssnano\dist\index.js:295:40
at Array.forEach (<anonymous>)
at E:\wamp\www\smm.yasmalik.com\node_modules\cssnano\dist\index.js:282:29
at creator (E:\wamp\www\smm.yasmalik.com\node_modules\cssnano\node_modules\postcss\lib\postcss.js:150:35)
at processCss (E:\wamp\www\smm.yasmalik.com\node_modules\css-loader\lib\processCss.js:199:16)
It was issue with my node_modules folder. there were some extra useless packages so simply i just deleted node_modules and install it again with following commands
Step 1
Delete node_modules manually
Step 2
Install the node_modules folder again:
npm i
Step 3
Update existing packages
npm update
That's it!
Probably you have some conflicts with versions of some npm packages.
Try to reinstall npm:
rm -rf node_modules
npm install

Resources