To import Sass files, you first need to install node-sass - node.js

Running create-react-app, I get the error in my create-react-app application:
To import Sass files, you first need to install node-sass. Run npm
install node-sass or yarn add node-sass inside your workspace.
I do have node-sass installed.
package.json:
"devDependencies": {
"node-sass": "^4.13.0"
}
project node_modules folder:
I've uninstalled, reinstalled, updated, cleaned cache, etc. How do I fix?

In my case I had the same problem even though node-sass was already installed in my project directory.
To import Sass files, you first need to install node-sass. Run npm
install node-sass or yarn add node-sass inside your workspace.
What I figured out is, my project was running on the react scripts installed globally, and there was an another version inside my local project directory. There was a conflict in getting the base path of 'node-sass'.
I uninstalled the local react-scripts and installed it again in the local project directory. Run,
npm uninstall react-scripts then
npm install react-scripts
That fixed my problem!

what worked for me was that I uninstalled global node-sass
and installed it in my current project directory
npm uninstall -g node-sass
npm install node-sass
make sure to stop npm start until after installation, if possible restart your system when installation is done

node-sass has been deprecated. Please install sass or dart sass to fix your issues.

I had the same issue and setting the SASS_PATH environment variable fixed it for me.
For example if you use docker-compose.yml then add:
environment:
- SASS_PATH=node_modules:src
Maybe someone else can explain why this was needed.

In my case below was my error,
./src/modules/TestListing/components/SurveyCard/index.scss
/usr/local/lib/node_modules/react-scripts/node_modules/css-loader/dist/cjs.js??ref--6-oneOf-5-1!
/usr/local/lib/node_modules/react-scripts/node_modules/postcss-loader/src??postcss!
/usr/local/lib/node_modules/react-scripts/node_modules/resolve-url-loader??ref--6-oneOf-5-3!
/usr/local/lib/node_modules/react-scripts/node_modules/sass-loader/dist/cjs.js??ref--6-oneOf-5-4!
./src/modules/TestListing/components/SurveyCard/index.scss)
To import Sass files, you first need to install node-sass.
Run `npm install node-sass` or `yarn add node-sass` inside your workspace.
The error was happening even though I had installed node-sass globally which was weird.
I figured react-scripts could not able to recognize node-sass in it's environment , Hence I have added node-sass dependency in globally installed react-scripts package
cd /usr/local/bin/node_modules/react-scripts
sudo npm install --unsafe-perm node-sass
In the above command I am actually installing node-sass to a react-script package which is a library, It could fix the issue in my case,
Becareful on the commands, Because I am dong --unsafe-perm, Read it before you do

Actually what worked for me was creating a new folder, creating a react app from there and transferring all the codes to that new folder. Not sure why the problem occurred in the first place.

I had this same problem and I noticed that npm install node-sass was breaking before full installation. I also tried npm uninstall -g node-sass which wasn't adding the package to the package.json file. What worked for me is npm install node-sass --save which installed node--sass and added it as a dev dependency to my package.json file

I had the same issue and I figured out it by installing sass moduele.
npm install sass
or
yarn add sass

node-sass is deprecated, use sass instead. But sass loader expects node-sass. No problem, we can install sass and trick sass-loader that sass is a node-sass
Install sass
npm install sass#^1.55.0 --save
In your package.json file, replace sass entry with this. We can use alias names in package json
node-sass": "npm:sass#^1.55.0
example
"dependencies": {
"axios": "^0.18.1",
"moment": "^2.29.3",
"node-sass": "npm:sass#^1.55.0",
...
works like a charm.

Generally, you should install node-sass:
npm install node-sass --save
# or
yarn add node-sass
How to import
#import 'styles/_colors.scss'; // assuming a styles directory under src/
#import '~nprogress/nprogress'; // importing a css file from the nprogress node module
Sass path variable
To use imports relative to a path you specify, and from node_modules without adding the ~ prefix, you can add a .env file at the project root with the variable SASS_PATH=node_modules:src. To specify more directories you can add them to SASS_PATH separated by a : like path1:path2:path3.

Related

node modules deleted. now npm is not installing

I deleted the node modules and package.json.lock file in my client side MERN Stack project folder and tried reinstalling the node modules by typing "npm install" command in the terminal. but it's showing me an error. 1. I have tried clearing cache using "npm cache clean --force".
2. I have tried reinstalling npm using "npm install -g npm".
3. I have tried updating the npm using "npm install -g npm#latest".
But nothing works. Please help me resolve this issue. below are my package.json file and the error in my terminal while installing node modules.
i was expecting that node modules will be reinstalled with all the dependencies mentioned in my package.json file.
NPM changed the way of resolving peer dependencies in v7, but this new way does not allow conflicting dependencies in the dependency tree. The simplest way to solve this would be to use the --legacy-peer-deps option to use the old way of resolving dependencies.
The hard(but better) way to solve it would be to spend some time to update the dependencies in a way that there is no conflicting dependency.

Cannot uninstall webpack from react-script

I was trying to make a todo-app in react, which is new to me. But after once installed webpack, npm start doesnt working. It gives me:
my-todo-react#0.1.0 start /home/hanna/Desktop/projects/my-todo-react
react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"webpack": "4.19.1"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:
/home/hanna/node_modules/webpack (version: 4.20.2)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
Delete node_modules in your project folder.
Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
Check if /home/hanna/node_modules/webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-todo-react#0.1.0 start: react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-todo-react#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/hanna/.npm/_logs/2018-10-02T10_39_06_361Z-debug.log
Create a .env file in the root directory of the project and add this line SKIP_PREFLIGHT_CHECK=true inside the file.
then try to run yarn start.
To solve this issue I had to uninstall webpack and webpack-dev-server from the node-modules folder and then install them again but with different versions.
Open cmd on the node-modules folder outside of your project folder
Uninstall webpack and webpack-dev-server:
npm uninstall webpack
npm uninstall webpack-dev-server
Delete the node-modules folder and the package-lock.json file from your project's folder.
Open the node-modules again
npm install webpack#4.19.1
npm install webpack-dev-server#3.1.9
Use this command on your project folder
npm install
It did the trick for me, hope it helps you too.
One solution I had was to go to my "Home" folder and delete the node_modules
folder and package-lock.json file.
Worked afterwards.
Since it looks like the project uses Create React App, Webpack is probably already a dependency in the package.json. So the easy way to install it is to just go to the project directory and type npm install (or yarn install) in the terminal.
If using the Webpack CLI causes errors, it's probably because there's a different version installed globally.
To uninstall it globally, type npm -g uninstall webpack.
I had similar problem today. I resolved with the following steps:
Execute npm ls webpack --> to find out that I have installed Webpack outside my folder ("like yours ... /home/hanna/node_modules/webpack).
Then cd into that location (/home/hanna/node_modules/) and execute npm install webpack#4.19.1.
That way I have the same version of Webpack like in my project folder.
After that, when I run npm start, it works fine.
Go to your project directory where you are running npm start and run the command
touch .env
If there is no pre-existing .env file in your project this will create it.
Got to .env file and add the following code (if you are on LINUX box you do this by typing nano .env otherwise just use a text editor.
SKIP_PREFLIGHT_CHECK=true
Save the file and try running npm start again.
This solution is exactly what is suggested in the error message and it worked for me
do this
first code in terminal this -->
yarn add --dev dotenv
create .env file in root directory then add below line in the .env file
SKIP_PREFLIGHT_CHECK=true
Go to /home/hanna and type npm i webpack#required_dependency. It should solve your problem.
If someone still facing this issue and uses yarn instead of npm can do (I am a mac user):
Open a terminal
Type yarn remove webpack
Come in to your project directory using your file explorer
Delete everything there
Open your code-editor
Delete hidden filers (ETC: .env or .gitignore files) if exists
In your project directory open a terminal and type npx
create-react-app . and hit enter.
And restart the app typing yarn start after download.
It worked for me. It downloaded the web pack which is needed from react-scripts.
I encountered the same issue and following worked for me:
Delete the node-modules folder and package-lock.json file
Downloaded and installed Node.js
npm install webpack#4.19.1
npm install webpack-dev-server#3.1.9
Deleted babel-eslint entry from package.json
Used this command on the project folder: npm install
Finally yarn start or npm start
I think if you have a webpack package installed globally it might cause such error. Removing it globally might solve the problem. That's what I did here and it works.
npm uninstall webpack
npm uninstall webpack-dev-server
Delete the node_modules folder and the package-lock.json file from your root directory
##thompsonmax##
Then you can now run your command to your app,
create-react-app react-app
Step 1: Create an .env file in the root directory
Step 2: add this line into your .env file: SKIP_PREFLIGHT_CHECK=true
Step 3:Again npm start
After a lot of trials, I found that the easiest solution is to install the required version of webpack in /home/hanna.
That is,
cd to /home/hanna
run npm i webpack#4.19.1
Then, the error will go away. Hope it helps.
Your problem is you installed webpack version: 4.20.2
You need to install an earlier version "webpack": "4.19.1"`
Your problem is you installed webpack version: 4.20.2
You need to install an earlier version "webpack": "4.19.1"` ..So
$npm uninstall -g webpack
and
$npm install -g webpack#4.19.1
Hope that helps
I think if you have a webpack package installed globally it might cause such error. Removing it globally might solve the problem. That's what I did here and it works.
Due to newer versions, this worked for me:
Open a terminal window (command prompt) on the node_modules folder outside of your project folder
Uninstall webpack and webpack-dev-server:
npm uninstall webpack
npm uninstall webpack-dev-server
Delete the node_modules folder and the package-lock.json file from your project's folder.
Open node_modules again
npm install webpack#4.28.3
npm install webpack-dev-server#3.1.14
Use this command in your project folder:
npm install
I couldn't find a way to uninstall the whole node module folder the only way is to delete the whole file using command line
rm -rf node_modules
npx create-react-app nameOfYourApp
find where is your nameOfYourApp and replace src folder with one from previous project
use new nameOfYourApp
If you have multiple node_modules folders with different versions of dependencies one may conflict with the other - do the following:
Follow steps 1-4 that are initially provided in project directory and commit updated changes locally~
i. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
ii. Delete node_modules in your project folder.
iii. Remove webpack from dependencies and/or devDependencies in the package.json file in your project folder.
iv. Run npm install or yarn, depending on the package manager you use.
Find the location of the node_modules folder that is not in your project folder ~ this line - (/home/hanna/node_modules/webpack)
Delete it
npm start
should work :)!
I also faced this issue. I had to install webpack#4.42.0 in the node_modules but after I installed webpack#4.42.0 there was an error displayed in the CMD:
`-- UNMET PEER DEPENDENCY webpack#4.42.0
npm ERR! peer dep missing: webpack#^5.1.0, required by terser-webpack-plugin#5.2.4
So installing webpack for node_modules didn't work. Then I used .env file to solve this.
First I typed npm add --dev dotenv in the project terminal.
Then I created the .env file and typed this code:
SKIP_PREFLIGHT_CHECK=true

How do I stop npm (v5.3.0) from automatically clearing local modules after install/uninstall?

I just upgrade my npm to v5.3.0 and run into a problem: after I install/uninstall a module, npm would automatically clear my local modules that I manually put into my node_modules. These local modules are not included into package.json. This is really annoying. Please help, thanks.
The solution is similar to the question How To Specify Local Modules As NPM Package Dependencies. The command is "npm install [path-to-local-module] --save". The local modules will be copied into the node_modules folder and their dependencies will be added to package.json.

Webpack Cannot find module ./lib/api/node.js # multi main

I removed all node_modules from my project and installed it again.
Before removing them everything was working fine. Now I'm getting an error at the end of webpack build :
After it happened I:
uninstalled webpack completely with -g option, installed it locally with npm install in my project.
uninstalled nodejs completely both with brew and manually removing all suspected files related to node or npm
installed nodejs with brew again.
Unfortunatelly I'm still getting the same error.
When I try to run the project with npm run dev where dev in package.json file is: "dev": "webpack-dev-server --progress --colors"
I'm getting the following error :
where ./app/index.jsx is the entry file for my project
Before all was fine, the directory structure was indentical, I haven't touched anything in the project apart from removing node_modules and installing it all again.
webpack version: 1.13.2 node version: 7.0.0 webpack-dev-server
version: 1.16.2
Any ideas greatly appreciated.
Thanks
Answering my own question just in case someone encounters the same issue:
I did the following steps:
remove webpack and webpack-dev-server from the package.json file
remove node_modules folder
run npm install
install both again (latest versions) npm install --save-dev webpack webpack-dev-server
After installing them the versions are as follows:
webpack: 1.13.3 (was 1.13.2 before) | webpack-dev-server: 1.16.2
Done!
1.remove foldernode_modules
2.run npm install
thx! my problems is solved by these two steps only !

npm install won't install devDependencies

On windows for some reason when I run npm install it won't install devDependencies. AFAIK it should. If I run npm install --dev devDependencies are installed. I don't understand why npm install doesn't install devDependencies too, but installs only dependencies. What could be the reason? How can I fix it?
Maybe something is wrong with my package.json? It is listed below if it may be helpful:
{
"name": "try-brunch",
"version": "0.1.0",
"private": "true",
"devDependencies": {
"brunch": "^2.0.4",
"cssnano-brunch": "^1.1.5",
"javascript-brunch": "^1.8.0",
"sass-brunch": "^1.9.2",
"uglify-js-brunch": "^1.7.8"
},
"dependencies": {
"jquery": "^2.1.4"
}
}
Check the NPM docs for install
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies."
The --only={prod[uction]|dev[elopment]} argument will cause either only devDependencies or only non-devDependencies to be installed regardless of the NODE_ENV."
Have you tried
npm install --only=dev
If you are worried that your package.json might be incorrect, best thing to do is this. Create a new folder, and run:
npm init --yes
Then:
npm install --save-dev brunch#^2.0.4
npm install --save-dev cssnano-brunch#^1.1.5
npm install --save-dev javascript-brunch#^1.8.0
npm install --save-dev sass-brunch#^1.9.2
npm install --save-dev uglify-js-brunch#^1.7.8
npm install jquery#^2.1.4 --save
And you should be good to go! Otherwise, will keep posting other options.
Check your npm configuration:
npm config list
npm gets its config settings from the command line, environment variables, and npmrc files. So check environment variables, and the npmrc file.
Still failing?
Ok, create a new folder, ideally somewhere else on your filesystem. ie. not in same folder hierarchy. For instance, C:\myNewFolder - the closer to the base C: drive the better.
Then run:
npm init --yes
Now run:
npm install underscore --save
and finally:
npm install mocha --save-dev
Does everything work as expected?
What I am trying to do is understand whether your problem is global, or something local to the previous folder and dependencies.
Check if npm config production value is set to true. If this value is true, it will skip over the dev dependencies.
Run npm config get production
To set it: npm config set -g production false
make sure you don't have env variable NODE_ENV set to 'production'.
If you do, dev dependencies will not be installed without the --dev flag
You can use the short way for installation dependencies only for development as follows:
npm i -D <dependencies-names>
I had a package-lock.json file from an old version of my package.json, I deleted that and then everything installed correctly.
I had a similar problem. npm install --only=dev didn't work, and neither did npm rebuild. Ultimately, I had to delete node_modules and package-lock.json and run npm install again. That fixed it for me.
I have the same issue because I set the NODE_ENV=production while building Docker. Then I add one more npm install --only=dev. Everything works fine. I need the devDependencies for building TypeSciprt modules
RUN npm install
RUN npm install --only=dev
Make sure your package.json is valid...
I had the following error...
npm WARN Invalid name: "blah blah blah"
and that, similarly, caused devDependencies not to be installed.
FYI, changing the package.json "name" to blah-blah-blah fixed it.
As of now you could use:
npm i --also=dev
So the way I got around this was in the command where i would normally run npm install or npm ci, i added NODE_ENV=build, and then NODE_ENV=production after the command, so my entire command came out to:
RUN NODE_ENV=build && npm ci && NODE_ENV=production
So far I haven't had any bad reactions, and my development dependencies which are used for building the application all worked / loaded correctly.
I find this to be a better solution than adding an additional command like npm install --only=dev because it takes less time, and enables me to use the npm ci command, which is faster and specifically designed to be run inside CI tools / build scripts. (See npm-ci documentation for more information on it)
In my case, the problem was that I had the NODE_ENV variable set to production in the same terminal session I ran npm install.
For my build to run properly I was not allowed to change the value of NODE_ENV so I forced npm to install all the dependencies by adding the --production=false flag to it: npm install --production=false as mentioned in the docs.
If you don't need NODE_ENV to be set to production you can simply type export NODE_ENV=development to your terminal to overwrite its value and run npm install again.
Got a similar error after running npm-check-updates -u. Solved it by removing node_modules folder and package-lock.json. After that a new npm install and everything worked.
My exception:
Failed to load parser '#typescript-eslint/parser' declared in
'package.json ยป eslint-config-react-app#overrides[0]': Cannot find
module '#typescript-eslint/parser'
As #Ale told, we can use npm i -D <some_module_name> or npm i --save-dev <some_module_name> now.
It seems command was changed at some point of node version.
Offical (npm dependencies and devDependencies) says following.
When you add the -D flag, or --save-dev, you are installing it as a development dependency, which adds it to the devDependencies list.

Resources