SPFX- Can not run gulp ser for the first time - javascript

I face this issue when I run gulp serve for the first time :
Error: Cannot find module '#rushstack/module-minifier-plugin'
Plz help me, Thanks!

1.Check your node_modules folder first.
When you install npm packages, npm will create a node_modules folder in your project root. It will also add packages you’ve installed to your package.json and package-lock.json files.You can confirm that a package has been installed by making sure it’s listed in your package and package-lock.json files. And double-check your node_modules folder to make sure the package is in a subfolder there.
2.Install the module.
As your gulp is complaining about the package missing,add it to your package.json and run npm install.

Related

NPM Install is not installing all of the files like it did previously

The first folder I installed NPM Install into, it created several folders and files.
node_modules
public
src
.DS_Store
package.json
package-lock.json
webpack.config.js
After this, npm start worked just fine.
Now I am starting a new project in this lesson, and I had to create a new folder and start over. So I followed the same procedure, now this time it only installed
package.json
package-lock.json
Nothing else was installed like the previous folder and time.
So now if I try npm start, I get the error MISSING SCRIPT: START
Can someone help me understand why everything isn't getting installed now like it did in the other directory just 15 minutes ago?
TIA
npm install only ever installs modules from package.json into the node_modules folder. You must have done something else before. Looks like it might have been npx create-react-app?

Why is npm install not installing packages into /node_modules folder?

When I npm install package, npm says that it successfully installed the package, but when I look for it in the node_modules folder, the package is not in the folder. When I npm install -g package, the package gets installed into the global /node_modules folder, so I have to drag the package from the global folder to the local folder.
Why is npm install not installing into my local /node_modules folder?
step 1) rm -rf ./node_modules from your root directory.
step 2) npm install.
The above commands first deletes your node_modules and then reinstalls all the packages that are found inside your package.json.
This is the same problem I was facing, both the above commands resolved the problem in my case.
If the above solution does not work in your case :
The problem is :
Data is not being fetched from the package.json, you must check whether you have written the correct statement or not inside your package.json.
There are a few things you can do to resolve this problem, as mentioned here.
First, try deleting your package-lock.json file. If you run npm install or npm i after that it should generate a brand new installation with no reference to an existing package-lock.json file.
If that doesn't work, try deleting your node_modules directory in your project. Then run npm install or npm i.
If THAT doesn't work, you should try deleting both the node_modules directory AND the package-lock.json. Then run npm install or npm i. This should resolve the issue.

Reinstall package from package-lock.json file

Consider this scenario:
I installed some packages like jquery and bootstrap with npm install.
After this npp make a package-lock.json file that describes installed package info.
When I push folder project to git server node_modules folder wasn't sent because of gitignore and only json file is placed on server.
If someone clone this repo he only has json file. How we can restore or reinstall all dependencies from package-lock.json file?
I tried npm install, npm ci, npm i but nothing restored.
Any idea?
Simply you need to run 'npm i' from your project folder. Also make sure, that all your dependencies are in your package.json file. And you need to track changes in your package.json file in future, because commiting 'node_modules' is a real bag thing. it will be always ignored by *.gitignore settings.
Also use "npm i %package% --save" to add current package to package.json.

create-react-app always throws babel error

Every time I create a create-react-app project it throws this error:
The react-scripts package provided by Create React App requires a dependency:
"babel-loader": "8.0.4"
Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-loader was detected higher up in the tree:
/Users/dalegrant/Desktop/hyberchat-dashboard/client/node_modules/babel-loader (version: 8.0.5)
I have tried downgrading to 8.0.4,
I've tried installing 8.0.5
I've even made sure all my dependencies for babel rely on a 8.0.5!
I have no idea what to do from here as the error persists for every create react app I now build!
This must be a common problem, does anybody have an idea on how to get around this?!
In your machine user folder there is a node_modules directory and package-lock.json remove them using rm -rf User/node_modules and rm -rf User/package-lock.json after that delete node_module directory and pack-lock.json file in your project run npm install again then it's works
Remove the babel-loader package (also globally):
npm uninstall babel-loader
npm uninstall babel-loader -g
Then run create-react-app again, it should install the correct dependency.
If you use the babel-loader somewhere else, pin the dependency there to ensure this problem does not happen again.
you probably installed node_modules in your main folders before. Search for them and remove.
In my case i have installed node_modules on my Home folder. When i removed files from this directory problem disapeared

Gulp: npm install gulp --save-dev was expecting to see just a gulp folder inside the node_modules folder

Wonder if someone can tell me if im doing something wrong?
Downloaded Node from there website
Installed Gulp globally (npm install --global gulp)
Made a folder and inside ran (npm init) which makes the package.json file
Installed gulp to the project (npm install --save-dev gulp)
This then adds gulp as a dependency inside package.json and creates a node_modules folder.
I was expecting to only see a gulp folder inside node_modules folder like so:
| node_modules
|-- gulp
But for some reason it's adding around 132 extra dependency folders, is this correct, should this happen? I would of thought these should be contained inside the gulp folder itself?
Im using a Mac, Node v5.2.0, NPM v3.3.12, Gulp v3.9.0
npm since v3 puts almost all dependencies to the node_modules directly.
Your dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's node_modules folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies.
References:
https://github.com/npm/npm/releases/tag/v3.0.0

Categories