I'm getting this error from my Node.js application:
ENOENT, no such file or directory '~/Desktop/MyApp/newversion/partials/navigation.jade'
I know the file is there because when I try to open the file using the exact copied and pasted path, it works. I also know the application is using the right directory because, well, it outputs it in the error.
I believe the previous answer is the correct answer to this problem but I was getting this error when I tried installing npm package (see below):
The fix for me was: npm init --yes
Tilde expansion is a shell thing. Write the proper pathname (probably /home/yourusername/Desktop/etcetcetc) or use
process.env.HOME + '/Desktop/blahblahblah'
I was also plagued by this error, and after trying all the other answers, magically found the following solution:
Delete file package-lock.json and the node_modules folder, and then run npm install again.
If that doesn't work, try running these in order:
npm install
npm cache clean --force
npm install -g npm
npm install
(taken from #Thisuri's answer and #Mathias Falci's comment respectively)
And then re-deleting the above files and rerunning npm install.
It worked for me!
First try npm install. If the issue is not yet fixed, try the following one after the other.
npm cache clean, then
npm install -g npm , then
npm install. Finally
ng serve --o to run the project.
__dirname
Gives you the current Node.js application's root directory.
In your case, you'd use
__dirname + '/Desktop/MyApp/newversion/partials/navigation.jade';
See this answer:
How can I get the application base path from a module in Node.js?
I had that issue using the path module:
const path = require('path');
And also do not forget to create the uploads directory first period.
Specifically, rm yarn.lock and then yarn install fixed this for me.
For those running Laravel Mix with npm run watch, just terminate the script and run the command again.
For me, it had my code folder in Dropbox on Windows 10. During the build process Dropbox would flip out over having more than 500,000 files. I moved my folder out and now it builds fine!
When this happened to me, it was when trying to run Karma tests in an Angular project. The tsconfig.spec.js file turned out to be incorrect. It was basically pointing to the wrong directory, and so the error was simply trying to tell me this.
For example, we had ../tsconfig.json instead of ./tsconfig.json, so the runner was looking for tests in the wrong folder. This may be a different use case from the OP, but the same error message brought me here and led me down the rabbit hole of trying the npm install solutions to no avail.
It usually occurs due to a mismatch in the npm version used while creating the package-lock.json that currently exist and the one you are using now.
Removing the package-lock.json and running npm install worked for me.
Sometimes you are just not in the right directory. Check that once and try "npm start" again.
Reason: I have the same issue, where a few guys work on one project and change package dependencies.
Solution: Just kill file package-lock.json and run npm i again
In my case, I was running the terminal in the wrong folder. Please make sure that you navigate to the folder containing your code (App.js and others) and then use a command prompt (for Windows) to open the code. I am using Visual Studio Code, so it is to type "code." after I have opened the command prompt in the exact folder where my code is in.
I ran into this upgrading a Phoenix app to 1.6, which does not use Node.js, so in fact it is not needed. However, elixir_buildpack.config had a reference to phoenix_static_buildpack.config, which defined node. Remove the reference, and the error goes away.
My problem was that I didn't have a package.json file in my working directory.
Another possibility is that you are missing an .npmrc file if you are pulling any packages that are not publicly available.
You will need to add an .npmrc file at the root directory and add the private/internal registry inside of the .npmrc file like this:
registry=http://private.package.source/secret/npm-packages/
Related
So oddly I really cannot find the answer to this question and after a few posts and docs I've looked at on NPM I've decided to ask the question - which may be a very basic one but doesn't seem to be implicitly addressed...
How do you uninstall npm from a dir?
Premis:
you npm init -y on the wrong directory
desired outcome:
to remove npm from that directory
I'm working on windows 10 / using git bash on VS code terminal
any help here would be appreciated -
Wally
All npm init does is setting up package.json for you (guided or not). If you just del package.json from the wrong directory, you should be good to go.
Deleting the package.json from the wrong directory should do the trick.
You will have to keep in mind that if in case you have run the npm i or npm install commands after npm init you will also have to delete the node_modules folder (as it usually takes plenty of disk space) and run npm i now in the correct directory.
I'm trying to install ionic on Windows but for some reason, I'm unable to. When I run the "npm install" everything looks fine, no errors, nothing weird happens, however when I try to run "ionic start" (or any ionic command, even just ionic -version) the shell says that "ionic is not recognized as an internal or external command".
I've tried everything but obviously, I'm still doing something wrong something. I tried uninstalling/re-installing/updating everything I could so I'm pretty sure that Nodejs and npm are fine.
From what I read online I found that this kind of error happens when the environmental variables are messed up, however, I don't exactly know what I'm supposed to change there. I've followed many guides and tutorials: some of them said that the PATH to npm should be under 'Roaming', others said that the PATH should be under 'Local', some said that it should be in 'Program Files' and others said that what matters is the order in which you write the PATH variables.
Some just said to reinstall node and after that everything should be fine but none of these suggestions worked.
Can anyone help me? What kind of environmental variables do I need to put in for this to work?
Should I remove the node and start from scratch? If so, where should I install node so that I don't have weird path problems later on?
If you need any additional information on the problem please say so. Thank you in advance for your time
It looks like your npm packages are not being installed on the default npm folder (%appdata%\npm). There's this command that shows you the root global npm folder, you can run npm root -g to check where npm is installing the packages and add that path to your PATH environment variable.
First, run the command bellow:
C:\> npm root -g
It will give you a path like this:
C:\my\actual\path\node_modules
Grab the path without node_modules (C:\my\actual\path\), and then add it to your PATH environment variable.
Warning: don't forget to remove the node_modules from the path it gave you.
Once you set your PATH variable, you need to restart your computer.
When I execute npm install I get this error
npm ERR! Error: EPERM: operation not permitted, rename C:\projects******\node_modules\react-async-script' -> 'C:\projects*******\node_modules.react-async-script.DELETE'
I am running the cmd as administrator
I ran npm cache clean before
I made sure all the other applications don't have anything related to node_modules open
In my situation this helped:
Before proceeding to execute these commands close all VS Code instances.
clean cache with
npm cache clean --force
install the latest version of npm globally as admin:
npm install -g npm#latest --force
clean cache with
npm cache clean --force
Try to install your component once again.
I hope this fix your issue. If not, you may temporarily disable your antivirus program and try again.
For me i just closed the Code editor (VS Code) and then run the same command. And that solves the issue for me.
I got it working when tried npm install with a force option to fetch remote resources even if a local copy exists on disk. Try running
npm install --force
Updated
For some of my colleagues this solution was not working. But we tried using yarn instead of npm. It works (faster as well) without any issues all the time
yarn install [package-name]
Not package.json, but for whatever reason, my node_modules/ had become read-only. Resetting that fixed this.
If you want to avoid the --force option (which is always a better approach), I suggest making sure that you have stopped running the project, as this is usually the main reason for locking the files in almost 90% of the cases I have seen
I suggest the following steps in this order:
1- In Angular stopping ng s and in React stopping npm start usually solves this issue because usually this error happens if a development server is running the project as it locks some files & then npm can't update them thus throwing this error
2- If the above doesn't work, then try closing the code editor that has the workspace opened in it (maybe it was locking some files or something)
So try closing the code editor & running:
npm install
3- If still it doesn't work, then maybe you can try the --force option
npm install --force
I was getting that same error and according to https://github.com/Medium/phantomjs/issues/19 it could be caused by your antivirus software. I disabled mine for the duration of the install and executed "npm install" on cmd as admin and it worked.
Hope this helps.
I was getting the same thing. I didn't find this anywhere but it hit me that our VMs tend to change files to a read-only state. So I opened package.json's file properties and deselected Read-only in the "General" tab.
Steps
Go to the package.json file.
Right-click and select Properties.
In the General tab, Attributes section, deselect Read-only.
Click Apply to apply the change.
This is a typical error caused by Antivirus. There is a workaround for cases like mine, where I can't disable A/V (Company Policy).
You have to change the polyfills.js inside Npm package:
[NODE_HOME]/node_modules/npm/node_modules/graceful_fs/polyfills.js
Look for this statement:
if (process.platform === "win32") {
Inside of this statement, there is a timeout making a retry in case of error. The problem is that in some cases, after the timeout, the file is still locked by the A/V. The solution is rip out the timeout and let this statement in loop. The change with the previous code commented:
if (platform === "win32") {
fs.rename = (function (fs$rename) { return function (from, to, cb) {
var start = Date.now()
var backoff = 0;
fs$rename(from, to, function CB (er) {
if (er
&& (er.code === "EACCES" || er.code === "EPERM")
/*&& Date.now() - start < 60000*/) {
console.log("Retrying rename file: " + from + " <> " + to)
fs$rename(from, to, CB);
/*setTimeout(function() {
fs.stat(to, function (stater, st) {
if (stater && stater.code === "ENOENT")
fs$rename(from, to, CB);
else
cb(er)
})
}, backoff)*/
if (backoff < 100)
backoff += 10;
return;
}
if (cb) cb(er)
})
}})(fs.rename)
}
As Martin Kearn pointed out in a comment, closing Visual Studio resolved these npm permission issues for me. Evidently VS sometimes locks files in node_modules.
I have had this issue multiple times only in Windows
I try these in the order usually.
npm install --force
Check if node_modules is set to read-only and
remove if it is
Delete node_modules/
Check if any editor is opened
that could have access to the root folder of the project
Reboot :(
Usually trying npm install after one of those steps will resolve it.
Trying to rename a file to another filename that already exists can cause an EPERM error on Windows.
In my case, something got locked up and a quick reboot resolved it.
Closing PHPStorm fixed the issue for me.
just close the VS Code to solve the issue for me
I am using macOS catalina ,
npm init
I got error
operation not permitted, uv_cwd
in 2021, this is how you can fix this problem.
very simple:
step 1: go to parent folder
cd ../
step 2: go to your project folder again,
cd your-project-folder
That is it. It works.
I did the following:
Upgraded the npm to the latest version: npm install -g
npm#6.5.0-next.0
deleted the npm-cache folder from: c:/users/[username]/AppData/Roaming/npm-cache
Did cache clean : npm cache clean --force
Ran the npm install.
I struggeled with this too.
I finaly a solution that works fine if you use nvm:
cd ~/.nvm/versions/node/{your node version}/lib/
npm install npm
and that's it.
I'm using the terminal in VSCode and I realized I was using the bash terminal instead of the node terminal.
npm was failing for me at scandir for:
npm install -g webpack
...which might be caused by npm attempting to "modify" files that were potentially locked by other processes as mentioned here and in few other github threads. After force cleaning the cache, verifying cache, running as admin, disabling the AV, etc the solution that actually worked for me was closing any thing that might be placing a lock the files (i.e. restarting my computer).
I hope this helps someone struggling.
I had the same problem. The reason for the error is unsupported characters in the path to the file. Replaced the cyrillic in English - it helped.
For some, AppRoot\npm folder could be an issue. Sometimes the AppRoot folder is marked as network shared and thus Antivirus blocks the stuff. Follow below link for complete solution.
https://alastaircrabtree.com/fixing-intermittant-eperm-operation-not-permitted-on-npm-install/
I hope this helps.
Open the command prompt as administrator and navigate to the project location and then run npm install. it worked for me.
I remounted my window disks with the metadata flag, and instantly helped: https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/
after that no need anymore to use sudo for npm commands as the metadata keeps windows and linux file/directory permissions in check.
In my case running npm: v6.9.0 && node: v10.16.1 on Windows, I had to run my CLI (git bash) as administrator. Then packages were installed without any warnings/errors
I had the same problem after updating to npm to 5.4.2, npm start giving the same error for most npm commands. Some solution suggest to run it with --no-optional, but it didn't always work.
Others suggested to downgrade, but I didn't want to downgrade.
I suspected that there was a problem with the installation, not sure what it was.
So I re-updated my npm:
npm i -g npm
and worked fine since then.
run the CLI as administrator always solve the problem for me
I came here with the same error, followed all the answers here, and none solved it. I started going through my package.json removing all suspicious packages. Removing this unnecessary one solved our problem. "npm": "^8.3.2"
I think it should be related to updating npm issue. As a workaround for now you can specify npm version as 8.3.1.
- name: Install latest npm version
run: npm install --global npm#8.3.1
I'm updating Angular 13 to 14 and I faced this issue.
None of these solutions worked so I just restarted the laptop and the npm i --force worked!
It seems like one process on the background is locking the access to certain node_modules files (you may have an ng serve running somewhere, or been launched by a git bash which you close but kept running on the background)
My answer is to do npm cache clean --force first. Then run npm install -g npm#5.3.0 to install npm 5.3.0 version. for me, this npm version works with no trouble.
I'm trying to install Gulp & Elixir on my Laravel project but I keep getting errors when I run 'npm install'. I've also tried 'sudo npm install' but no luck there.
My Node version is: 1.4.14
It switches between these two:
For this error there was a solution posted here: https://harvsworld.com/2015/how-to-fix-npm-install-errors-on-vagrant-on-windows-because-the-paths-are-too-long/
But this has not solved the issue seeing it still happens after following the steps.
I also sometimes get these errors (the list goes on...):
Anyone know a solution? I haven't found anything yet after a couple hours of searching..
After a long search I eventually found the solution.
Seeing I'm using Homestead / Vagrant, I was using PuTTY. This was my first mistake.
Just simply use Git Bash, just make sure you run it as an administrator &
change the directory to your Laravel project.
The second thing you need to do is make sure you don't have a 'node_modules' file in your project. Just remove the files by doing:
rm -rf node_modules/
Followed by:
npm install
Everything should work now. It's a dumb mistake but hopefully through this post, people will not make the same one as I did and waste alot of time doing it..
Cheers!
You should first install node in your local machine.
Then, navigate to your project folder and run (again on your local machine!):
npm install gulp --save-dev
I'm just getting started with webpack and am having difficulty getting the multiple-entry-points sample to build. The webpack.config.js file in the example includes the line
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
which fails for me with the error
Error: Cannot find module '../../lib/optimize/CommonsChunkPlugin'
Searching around, I found other examples of using the CommonsChunkPlugin with the expression
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin("common.js");
which fails with the error
ReferenceError: webpack is not defined
Some more searching found a number of examples including
var webpack = require('webpack');
and my build now fails with
Error: Cannot find module 'webpack'
I'm at a loss as to how to proceed.
Link globally installed package to your project:
npm link webpack
Checkout the official documentation of yarn link.
I solved the same problem by reinstalling, execute these commands
rm -rf node_modules
rm -f package-lock.json
npm install
rm is always a dangerous command, especially with -f, please notice that before executing it!!!!!
While working on windows, I've installed webpack locally and it fixed my problem
So, on your command prompt, go to the directory of which you want to run webpack, install webpack locally (without the -g) and enjoy...
Run below commands in Terminal:
npm install --save-dev webpack
npm install --save-dev webpack-dev-server
Seems to be a common Windows problem. This fixed it for me:
Nodejs cannot find installed module on Windows?
"Add an environment variable called NODE_PATH and set it to %USERPROFILE%\Application Data\npm\node_modules (Windows XP), %AppData%\npm\node_modules (Windows 7), or wherever npm ends up installing the modules on your Windows flavor. To be done with it once and for all, add this as a System variable in the Advanced tab of the System Properties dialog (run control.exe sysdm.cpl,System,3)."
Note that you can't actually use another environment variable within the value of NODE_PATH. That is, don't just copy and paste that string above, but set it to an actual resolved path like C:\Users\MYNAME\AppData\Roaming\npm\node_modules
I was having this issue on OS X and it seemed to be caused by a version mismatch between my globally installed webpack and my locally installed webpack-dev-server. Updating both to the latest version got rid of the issue.
I was facing same problem, and I solved through this command, check this out will solve your issue.
rm -Rf node_modules
rm -f package-lock.json
npm install
Installing both webpack and CLI globally worked for me.
npm i -g webpack webpack-cli
If you have installed a node package and are still getting message that the package is undefined, you might have an issue with the PATH linking to the binary. Just to clarify a binary and executable essentially do the same thing, which is to execute a package or application. ei webpack... executes the node package webpack.
In both Windows and Linux there is a global binary folder. In Windows I believe it's something like C://Windows/System32 and in Linux it's usr/bin. When you open the terminal/command prompt, the profile of it links the PATH variable to the global bin folder so you are able to execute packages/applications from it.
My best guess is that installing webpack globally may not have successfully put the executable file in the global binary folder. Without the executable there, you will get an error message. It could be another issue, but it is safe to say the that if you are here reading this, running webpack globally is not working for you.
My resolution to this problem is to do away with running webpack globally and link the PATH to the node_module binary folder, which is /node_modules/.bin.
WINDOWS:
add node_modules/.bin to your PATH.
Here is a tutorial on how to change the PATH variable in windows.
LINUX:
Go to your project root and execute this...
export PATH=$PWD/node_modules/.bin:$PATH
In Linux you will have to execute this command every time you open your terminal. This link here shows you how to make a change to your PATH variable permanent.
On windows, I have observed that this issue shows up if you do not have administrative rights (i.e., you are not a local administrator) on the machine.
As someone else suggested, the solution seems to be to install locally by not using the -g hint.
for me, it is a wrong error feedback.
there was config error in webpack.config.js,
delete the file and start over solved my issue
Open npm command prompt and -- cd solution folder
and then
just run npm link webpack in NPM cmd prommt and re build..
You can try this.
npm install --only=dev
It works for me.
In my case helped me changing the parent folder name and remove some & from this name, you can also try changing the name or folder where you keep your code.
Nothing suggested above worked for me (including the NODE_PATH variable). I created a sym link of "node_modules" from my local folder to the global AppData(eg below) and it worked like charm.
C:\Users\mmoinuddin\AppData\Roaming\npm>mklink /D node_modules c:\essportreact\day1\node_modules
symbolic link created for node_modules <<===>> c:\essportreact\day1\node_modules
C:\essportreact\day1>webpack
Hash: 2a82a67f90f9aa05ab4a
Version: webpack 1.15.0
Just found out that using Atom IDE terminal did not install dependencies locally (probably a bug or just me). Installing git bash externally and running npm commands again worked for me
I had a ton of issues getting a very simple .NET Core 2.0 application to build in VS 2017. This is the error from AppVeyor, however it was essentially the same thing locally
(some paths omitted for security) :
Performing first-run Webpack build...
module.js:327
throw err;
EXEC : error : Cannot find module '......../node_modules/webpack/bin/webpack.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:140:18)
at node.js:1043:3
csproj(25,5): error MSB3073: The command "node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" exited with code 1.
Build FAILED.
I stumbled upon this question and answer, and I noticed my local instance also had the same warning sign over the {Project Root} -> Dependencies -> npm folder. Right clicking and hitting "Restore packages" got everything loaded up properly, and I was able to build successfully.
npm link webpack
worked for me.
My webpack configuration:
"webpack": "^4.41.2",
"webpack-dev-server": "^3.9.0",
"webpack-cli": "^3.3.10"
For Visual Studio users: Right click on the npm folder and "Restore Packages".
While the suggested solution (npm link webpack) worked locally, on my CI (GitHub actions) I had the same problem, and to resolve it I used:
npm i --save-dev webpack
Laravel Users
If none of the above options work for you, then you probably need to install Laravel-mix correctly. Here is how:
npm install laravel-mix --save-dev
Now create a webpack.mix.js file using this command:
touch webpack.mix.js
Add this code into your webpack.mix.js file:
mix.js('resources/js/app.js', 'public/js').postCss('resources/css/app.css', 'public/css', [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
]);
You probably will also need to create a tailwind.config.js file using the command touch tailwind.config.js and then add this code ainto it:
module.exports = {
content: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
theme: {
extend: {
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require('#tailwindcss/forms')],
};
Finally run npm run dev
So there are quite few possible issues, in my case on windows:
I moved my project to a folder with an & in the name, which is fine for windows but it break npm. My solution was to remove the & from the name.
test&mocking -> test_and_mocking
What solved it for me was that the path to webpack.config was wrong in build.js
rm -rf node_modules
rm -rf package.json-lock
npm install --force or npm install --legacy-peer-deps