I am new to Node. I just tried installing nodemon and that resulted in a huge node modules folder with more than 100 folders. Is nodemon actually that big or am I doing something wrong. I used the following commmand:
npm i nodemon -D
Because nodemon is built with other npm packages. You can see the dependencies in its official page:
https://www.npmjs.com/package/nodemon
And in turn the dependencies may depend on other modules. That's why node_modules can have many files. But don't worry, this is normal.
Related
Browsing stack overflow, I noticed that a common fix is make sure that dotenv is in dependencies and not just devDependencies. Here's a screenshot of the log and the package.json. You'll notice that dotenv is indeed in my dependencies. I also deleted and reinstalled node_modules multiple times but still no luck.
I am requiring the dotenv at the top of my server file as shown here
I fixed the issue. I decided to try uninstalling dotenv and reinstalling, this worked. Apparently, this was different from deleting node modules and npm install.
I see dotenv is added to a devDependency: devDependency are special and are only installed when you do a npm install on the package.json which contains them. Usually, you'll add your development tooling (like test runners, etc.) in devDependencies since they are not required for the application to run.
When we run an application in production, we install dependencies using npm install --production which only installs the dependencies mentioned in the dependencies section of package.json. This is also what Heroku does for you (check their buildpack for Node.js!)
To install a devDependency, you would do: npm i -D <package name>; and to install a production dependency (like your web framework like express), you'd do npm i -S express.
Try running npm i -D dotenv and check if it works (it may also work if you just do a npm i dotenv.
I installed webpack into my react project, but the same error occurred every time when I use npm start:
The react-scripts package provided by Create React App requires a dependency:
"webpack": "4.42.0"
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:
C:\react\minimoj\node_modules\webpack (version: 4.43.0)
I tried to remove package-loc.json file + all node_modules + remove webpack name from package.json and reinstall it with npm install. Also I tried same with yarn, but it didn't help. I see that in node_modules version is 4.43 and after I use npm install webpack in the file package-loc.json it shows 4.43, but at the moment when I use npm start it changed to 4.42 and error occur. In addition I also reinstall node.js but it didn't help.
create .env file and add SKIP_PREFLIGHT_CHECK=true
I had similar with a newer webpack version being installed than what react_scripts required.
To fix I deleted webpack and webpack-dev-server from my project's node_modules, went to a console outside of the project dir and ran
npm uninstall webpack
npm uninstall webpack-dev-server
Then ran
npm install
npm run build
And all was well, as my package.json was correct without change.
Since webpack is mostly focused on common js according to some websites, I just tried rollup for my react project and it proved to be much more effective as it supports es+. I would highly recommend it. I took a couple minutes to have everything setup and ready. Also, as a good practice it is better to use yarn as npm has had a lot of known issues for node app management.
I decided to create React app under Linux and I've used those commands:
npm install -g create-react-app
create-react-app my_app_name
npm start
At this point I've recieved message:
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/ktw/node_modules/webpack (version: 4.24.0)
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:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
4. 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:
5. 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.
6. Check if /home/ktw/node_modules/webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
I've done literally every step from this list but unfortunately - with no results.
I've already tried:
chown -R user: node_modules,
npm cache clean --force,
rm -rf node_modules && rm ./package-lock.json && npm install
and I have no idea what is going on.
Do you guys have any idea how to fix that?
It looks like you may have forgotten to do Step #3: Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
If you are doing the steps as you outline above, when you do npm install again, because Webpack is still in your package.json, it'll reinstall and continue the issue.
Local NPM modules are no longer installing correctly for me in my projects node_modules dir. This has just started happening.
I set up a test dir with a package.json:
{
"name": "test",
"version": "0.0.0"
}
Then ran this command:
npm install grunt --save-dev
This is what I get in my node_modules dir:
Opening the grunt dir you can see there’s no node_modules:
Some of the NPM modules that appear in the root are what appears to be NPM modules belonging to the grunt NPM module, and some I have no idea where they are coming from? E.g. abbrev, esprima, graceful-fs, etc.
I used to get this:
project
│
└───node_modules
| │
| └───grunt
|
└───package.json
I’ve tried completely removing Node.js and NPM from my machine (Mac OS X 10.10.5) following these instructions. Then reinstalling it outside of Homebrew (where it was previously installed) which didn’t change anything. Then completely removing Node.js and NPM again and reinstalling it with Homebrew but this time I applied this. Again this didn’t fix anything.
Not sure what’s going on?
This is expected behavior. When you install grunt, npm recursively installs all its dependencies. These may be put to grunt/node_modules or may be put on the same level as grunt (directly in the top level node_modules). Both these options will work, which is because of how node works: if grunt requires some package (for example, colors) and node does not find it in grunt's node_modules directory, node tries to find the package in the parent's dir, then in grandparents dir and so on.
Out of these two options, older npm versions prefer the first option, newer versions prefer second option (i.e. more flat dependency tree), which is exactly your case.
In your case, packages such as 'async' or 'colors' are grunt dependencies (check out its package.json), 'abbrev' is not direct dependency of grunt, but probably it is dependency of some other dependency.
More reading:
https://docs.npmjs.com/cli/dedupe
https://github.com/alexanderGugel/ied
https://docs.npmjs.com/cli/shrinkwrap
I recently started a new node project and ran npm install *name* --save for both express and nodemon and noticed that 20-30 folders appear in my node_modules folder related to the two packages instead of just express and nodemon. This has never happened when I have run this command with previous projects. Is there any reason why this is happening now?
I expected my node_modules folder to only have "express" and "nodemon"
npm version: 3.3.6
node version: 5.0.0
Stumbled upon your post with a Google Search and thought I'd link the answer :
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.
See npm#3's release notes.