Node/NPM not resolving modules from local node_modules folder - node.js

I am on Windows and my app is located at folder H../my-app. my-app has a node_modules folder which has all the required modules installed. However, when I compile the app by typing the script command in terminal, Node starts looking for modules in C:/Developer... and gives error that xyz module not found, even though it is present in my-app/node_modules. Why is this happening?
I understand that Node will look for modules in global directory if not found locally, but that's also not the case here as my global node directory is in H drive, not C.
I cannot log the entire error here as I am working on a remote machine and there is no way I can copy code out of it, but here is a line of error as logged into npm-debug.log:
verbose stack Exit Status 1
verbose stack at EventEmitter.<anonymous> (C:..\node\6.3.1\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16

Related

how to fix "Error: Cannot find module '/home/container/index.js'", I've tried everything

So the host that I use for my discord bot died so I downloaded all the code and tried hosting it on my PC. But I get the following error.
Error: Cannot find module '/home/container/index.js
I've tried everything I can:
updated nodejs
reinstalled all my packages
Changed package.json
How can I fix this?
Cannot find module means you are trying to run non-existent file.
Ensure there is index.js in your working directory. If not,
Use cd to go to the directory where it is (usually it's src near the package.json)
Run node ./index.js
Many time people have just the problem of command line to run file,
as windows and linux have
different syntax to run .js file
i.e. node ./index.js for linux
and node .\index.js for windows

Windows 10 Can no longer run a javascript file through node.js or display version nor npm

I am on Windows 10.
Node Js version V10.16.3 is successfully installed. Npm version 9.x ok also.
I was working for several weeks on a vuejs project using Visual Studio Code.
Suddenly 2 days ago, the npm start command stopped working.
After investigation and having deinstalled and reinstalled nodejs several times (with deletion of directories), I keep ending up with the same problem I'm describing below:
Nodejs REPL console is working fine. When I type process.version > it displays V10.16.3
node -v or node --version display nothing but a blank line in the cmd window.
node test.js (console.log("hello");) does nothing (no execution at all), except printing a blank line.
If I type node test.js > test.log: nothing is written to test.log.
npm -v or npm --help open several extra windows in the cmd window.
The 1st extra window is titled "C:\Program Files\nodejs" and closes straight away.
The 2nd extra window is titled "npm" and closes straight away.
Then the prompt goes back to the current cmd window where I typed the command npm --version or -v.
Then another cycle starts with:
The 1st extra window is titled "C:\Program Files\nodejs" and closes straight away.
The 2nd extra window is titled "npm" and closes straight away.
And finally it comes back to the current cmd window with no output at all except for a blank line.
Sometimes, I can see the version number "9.x" being displayed in one of the npm titled window.
npm -list does the same with opening of the 4 successive windows, and a list of node modules is displayed in the last one, titled "npm", before the window closes.
I checked npm.cmd and it is OK
When I type node "C:\Program Files\\node_modules\npm\bin\npm-cli.js" -v, it displays nothing but a blank line.
I read all questions and answers in stackoverflow but none is related to my case except this one: npm -version displays nothing, but there is no solution provided.
Can someone help me, please?
C:\Program Files\nodejs> node -v
C:\Program Files\nodejs> npm -v
C:\Program Files\nodejs> node "C:\Program Files\\node_modules\npm\bin\npm-cli.js" -v
I expect to display node version and npm version to be displayed in the current cmd line and I expect node test.js to work and get my "hello" as it was working 2 days ago...
I provide somme complements and details with some screenshots :
1) Node console REPL
Node console REPL works correctly
2) Cygwin console
Node works with cygwin
3) Powershell console
Node -v, npm -v, node script.js execute but in a temporary separate popup window > Before this bug with node cmd > all displays were output directly in the console without popup window
4) node cmd window
Nodejs command prompt run by node.cmd script no longer works > no version number is displayed. npm command open multiple popup windows with execution of npm but terminates with node error
11 silly lifecycle projet-test#1.0.0~dev: Returned: code: 9 signal:
null 12 info lifecycle projet-test#1.0.0~dev: Failed to exec dev
script 13 verbose stack Error: projet-test#1.0.0 dev:
webpack-dev-server --inline --progress --config
build/webpack.dev.conf.js 13 verbose stack Exit status 9 13 verbose
stack at EventEmitter. (C:\Program
Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:210:5) 13 verbose
stack at ChildProcess. (C:\Program
Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:210:5) 13 verbose
stack at maybeClose (internal/child_process.js:1021:16) 13 verbose
stack at Process.ChildProcess._handle.onexit
(internal/child_process.js:283:5)
I think you should completely uninstall Nodejs and NPM and reinstall. Some files might have been corrupted.
To uninstall NodeJs and NPM completely pls follow this :
How to completely remove node.js from Windows
Then install the Nodejs required Version. When installing, please select all module as shown below
IMP: Don't use NPM version higher than 6.11.3
Alternatively, if you don't want to uninstall select repair option by running installer again
I found a aworkaround doing a silly thing :
I renamed node.exe in C:\Program Files\Nodejs as mynode.exe
I modified nodevars.bat, npm.cmd by replacing node.exe by mynode.exe in each node.exe call
I wrote a simple node.cmd file containing these lines and placed in C:\Program Files\ directory:
:: Created by DR
#ECHO OFF
SETLOCAL
SET "NODE_EXE=%~dp0\mynode.exe"
IF NOT EXIST "%NODE_EXE%" (
SET "NODE_EXE=mynode"
)
"%NODE_EXE%" %*
running node -v being node.cmd works
I know it is a stupid method but it works in my very specific case. It means that 'something' prevents to run node.exe in command line but allows node.cmd that launchs mynode.exe.
I someone could explain/found out what is wrong in my windows configuration, I would be very thankful.
( I checked for any other node.exe, checked path and register, install/uninstall node, etc. BUT, I always stick with the same probleme although running node.exe in command line was working vey well before I encountered the crash of eslint when editing a simple vue.js file with visual studio code editor. since that there is a parameter in my windows confinguration that blocks node.exe in dos command line and only within command line window. For recall, node -v (with node.exe) works well in cygwin...

How to deploy Nuxt.js to Elastic Beanstalk?

I am very new to AWS and i have been following the tutorials out there but couldn't find the answer. So, what i did was i created simple nuxt application, no changes to the framework's script or anything. I set my elastic beanstalk to run node.js settings. and then i tried to deploy my /dist folder(using nuxt build) with the application's json folder as told by every tutorials. but it gives me this this is what it looks on my webpage
I think i have something wrong with which folders i deploy or do i have to actually deploy via the aws CLI, would that make a difference at all?
eb log :
-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
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! /tmp/.npm/_logs/2019-09-29T16_00_28_939Z-debug.log
> portfolio#1.0.0 start /var/app/current
> cross-env NODE_ENV=production node server/index.js
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/var/app/current/server/index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
The nodejs logs indicate to me that there is an issue with the build, an issue with how it's zipped, or an issue with your start command.
The most common is incorrectly zipping source files
When you create a ZIP file in Mac OS X Finder or Windows Explorer, make sure you zip the files and subfolders themselves, rather than zipping the parent folder.
In other words, do not right click the dist folder and click "zip", select all the files and folders (including hidden ones) and zip those. Elastic beanstalk, and many other AWS services, expect the zip to unpack into a flat structure, and not contain the parent folder when unzipped.
If this does not solve your problem, make sure you're zipping the correct folder. Try deleting your .nuxt and /dist folders, and running npm run build locally. The folder that is produced (defaults to .nuxt) is the folder whose contents need to be zipped.
The reason it is throwing that error is because your launch command starts with cross-env. When it sees that it tries to run the globally installed package cross-env but it is not available globally, so it throws that error. There are a few possible ways to address this:
The easiest is to just change the start command to use a relative path to the locally installed version of cross-env, so your command should look something like this:
node_modules/cross-env/src/bin/cross-env.js node server/index.js
You might also try adding npx to the front of your command, like so:
npx cross-env NODE_ENV=production node server/index.js
This should work but I have found that sometimes I get errors with specific packages, from what I can tell it is a bug with npx but I haven't had time to look into it. Notably I did see this bug with a nuxt js app specifically so you might too, however I was using the nuxt cli which you are not.
The third option is you could look into installing the package globally using ebextensions. In my work I haven't come across a situation where that has been necessary.

NPM Link Error EEXIST -4075 when linking multiple folders

I am working on a installer, after we install the files we run a script that uses NPM Link to setup some folders.
When I run the script on my VM it works without any errors/warnings. When I try to run it on my own machine I get this error:
84 verbose node v9.5.0
85 verbose npm v5.6.0
86 error path C:\Users\me\AppData\Roaming\npm\node_modules\module
87 error code EEXIST
88 error errno -4075
89 error syscall symlink
90 error EEXIST: file already exists, symlink 'C:\Users\me\AppData\Roaming\npm\node_modules\module' -> target folder
91 error File exists: C:\Users\Me\AppData\Roaming\npm\node_modules\module
92 error Move it away, and try again.
93 verbose exit [ -4075, true ]
Now I know this file already exists, I already linked it. But I am not getting this error on my VM where I do the exact same thing. Do I need to remove the node_module everytime I link it? That can't be right, right?
I already re-installed NodeJS on my own machine.
This is basically what I do:
call NPM link ..\Folder1
call NPM link ..\Folder2
call NPM link ..\Folder3
And I have to do this for multiple folders. Some folders need to have all 3 linked, others just the 1 or the 2. So for every folder I do this in, I get the error for every operation. It does the linking but I really want to get rid of the error, especially cause it works on my VM.
I already tried to go in to the folders and call NPM Link (without arguments) but that doesn't seem to do anything.
Found out what was the problem.
First you run NPM Link (No arguments) in the source folder.
NPM Link
Then you run NPM Link module_name in the target folder.
NPM Link [module_name]
So use the module_name instead of the location.

node jitsu cannot find local modules

I have an application successfully working locally so I know the code works. However when I go to deploy to node jitsu I get an error that it cannot find a local module. Here is what I have:
File Setup:
/index.js
/config/config.js
index.js
var cfg = require('./config/config.js');
When trying to deploy node jitsu is giving me an error:
Error: Cannot find module './config/config.js'
Since all this code works locally I do not believe this is a coding issue. I am under the impression that local modules do not need to be included in package.json but perhaps they do for node jitsu? I read their documentation but cannot find anything special for local modules.
Thanks!
Local modules like this should work properly.. so long as you don't have it in .gitignore or .npmignore.
Modules in the node_modules directory require that you add it to the bundledDependencies array in your package.json file.
An easy way to check for whether the file is included in your deploy is to run tar -tf $(npm pack).
I had this exact same error on deploy, but caused by a different root cause. In case anybody stumbles into the same problem:
File Setup:
/public/Data/TargetData.js
app.js require statement:
var target = require('./public/data/TargetData.js');
My local Mac OSX environment allowed the capitalization difference of /data/ vs. /Data/ - the Nodejitsu server did not.

Resources