npm 3 globally installed package not working - node.js

I have installed this module globally however it fails with an error when run due to a dependency error however if I run my local copy by running the command
node ./bin/xl-json
the command works. I believe when running the npm i -g xl-json command that dependencies aren't being installed properly. Any ideas why one way works and the other doesn't?

The reason it doesn't work is because it is not [exactly] the same command you are running.
If you look at the error you see:
if (cptable === 'undefined') cptable = require('./dist/cpexcel');
^
ReferenceError: cptable is not defined
When you run the global command xl-json, the .cmd file (created by npm) takes precedence. iow. npm creates a file called xl-json.cmd which is a wrapper that invokes xl-json in the bin folder.
This file uses the strict option which the code should use but does not.
Try your command with --use-strict and you should see the same error message. i.e.:
node --use-strict ./bin/xl-json

Related

Node,exe not found despite correct environment variables CI build windows

I'm dealing with a strange issue. When yarn install is ran during my automated CI build, I get the following error:
error C:\GitLab-Runner\builds\6sT6aNYk\0\[redacted]\node_modules\fibers: Command failed.
Exit code: 1
Command: node build.js || nodejs build.js
Arguments:
Directory: C:\GitLab-Runner\builds\6sT6aNYk\0\[redacted]\node_modules\fibers
Output:
'node' is not recognized as an internal or external command,
operable program or batch file.
'nodejs' is not recognized as an internal or external command,
operable program or batch file.
My environment variables are correct. I've manually browsed to the directory, and executed the same command using powershell. Then the command does not fail, and node is found in its installation directory. Powershell is the runner configured for this system/project.
During the CI build I can See node.exe spawning under gitlabrunner.exe. So the path for the process is correct. It's just yarn install that fails to find node.exe.
I'm not a javascript developer, and I do not know how to dive deeper into what is happening. How can I see what causes this problem? Has anyone experienced something like this before?
Other things I've looked at:
path length disabled
Building from other directories in the system (manually, it all works)
Removing node & npm and re-installing
Edit:
The issue also occurs if I use npm install instead of yarn install.
I found the problem. Another item in my build chain was adding items to the path in a loop. previously this was not a problem, but maybe an update added more items.
The solution was to clear the environment and add the original path back.

how to set default node read location for extension in vs-code?

Pre-problem
I install npm and node using nvm, so that make my npm and node location in directory
npm /home/putrapc/.nvm/versions/node/v8.9.4/bin/npm
node /home/putrapc/.nvm/versions/node/v8.9.4/bin/node
all i install in stable version
The problem
I start using vs-code and there is always error notification that annoy me, like this
I realize that problem because the extension in vs-code like jsHint, flow, Javascript standard style, etc doesn't read any of my npm package properly. Yes it cause the directory isn't correct, how to change default read directory in vs-code ?
My eslint directory
/home/putrapc/.nvm/versions/node/v8.9.4/bin/eslint -> /home/putrapc/.nvm/versions/node/v8.9.4/lib/node_modules/eslint/bin/eslint.js
i had eslint installed as package, but the vs-code still didn't read it. How to correct this?
I was encountering similar issues with VS Code extensions encountering issues when trying to run Node with error messages such as
/usr/bin/env: ‘node’: No such file or directory
The simplest solution I found to this is to use a terminal to start Visual Studio in the folder that you're trying to open from
This can be done by navigating to the folder you're trying to open in Code, opening a terminal there, and typing in
$ code .
The above behaviour seems to happen because NVM sets its own variables for the node location and that is what is used by default in your terminal session. You can check these using
env | grep NVM
This returned the following for me
NVM_DIR=/home/saikat/.nvm
NVM_CD_FLAGS=
NVM_BIN=/home/saikat/.nvm/versions/node/v12.0.0/bin
Also, trying to get the current Node location using which returns the following
$ which node
/home/saikat/.nvm/versions/node/v12.0.0/bin/node
When starting Visual Studio Code from anywhere apart from the terminal, the above NVM variables don't get set and hence the extensions try to find node at the default location /usr/bin/env and are unable to find it there and hence fail

node 6.11.3 NODE_EXE not found in IntelliJ

I've updated my project to use node 6.11.3. When I now try to start a npm-script by using the Run-configurations provided from IntelliJ, I always receive the following error:
Error: Failed to replace env in config: ${NODE_EXE}
Important: This error appears only if I start npm from within my project. If I use the windows cmd, the error doesn't appear.
What could possibly have changed between node 6.11.2 and 6.11.3? Because with the prior version, everything worked fine.
A workaround for me is to add the NODE_EXE variable to my run configuration, but In my opinion, that shouldn't be needed, because it worked in 6.11.2 too.
Looks as if you have ${NODE_EXE} variable set in one of your npmrc files (see https://docs.npmjs.com/files/npmrc#files), and it can't be properly expanded for some reason when you run your script in the IDE.
is the issue specific to certain project?
how many npm versions do you have installed? Please check that npm chosen in Node.js Interpreters dialog is the same as you use in cmd shell?
please create an env.js file with console.log(process.env) and try running it via npm ("env" : "node env.js") in both cmd console and WebStorm - what is the result?

Can't seem to get Node js and NPM up and running: Reference Error on every command

I just installed node-v4.4.5-x64 and I'm using Windows 10 but everything I type into the command line (even -h and --help) gives me a ReferenceError: h is not defined. I'm just getting started trying to use NPM so i'm pretty new to this. What am I doing wrong? How can I get started with NPM?
If you are using Visual Studio 2017 run npm from Package Manager Console, not Node.js Interactive Window
The error occurs because you're running the npm commands from within the node REPL: /nodejs/node.exe starts the node REPL. The reason the error is a ReferenceError is because the variable npm is not defined within the REPL.
What you want to do is run the commands inside the terminal. You'll need to exit the node REPL by pressing Ctrl + D. You should be in the terminal now.

Node.JS Express Authentication App Creation TypeError

I'm working through a tutorial on Node.js that begins with a simple authentication program. This is the second time I'm doing this tutorial, and the first time, everything worked fine. However, upon uninstalling node and starting from scratch (installing node.js and express via npm), the instantiation of authentication errors out as below.
program.confirm('destination is not empty, continue? ', function(ok){
^
TypeError: Object #<Command> has no method 'confirm'
at C:\Users\Kyle\AppData\Roaming\npm\node_modules\express\bin\express:251:15
at C:\Users\Kyle\AppData\Roaming\npm\node_modules\express\bin\express:382:5
at Object.oncomplete (fs.js:107:15)
I'm on a windows machine, running Node.js v0.10.20 and express v3.4.1.
Is this a result of the inconsistent -g flag install referenced here?
EDIT: Express initializes apps fine in other directories, even those with the subdirectory Node.js. The path to this problem folder is C:\dev\Node.js\ ...any idea why Express refuses to initialize something in this folder?
Try:
Remove your directory
"C:\Users\Kyle\AppData\Roaming\npm\node_modules\express\node_modules\commander".
Install node module "commander 1.3.2" globally.
Command line: $ npm install -g commander#1.3.2
Run "express" again.
It seems to be the problem referred to the new version(2.0.0) of the commander module.
It works on my mac.
Good luck~
I had the same problem. Rather than fix the problem, you can fix the source of the problem (not specifying an empty directory). In my case I was specifying an empty directory, but it was associating that with the previous switch.
I had to change:
node_modules/.bin/express -s -e -c ./server
To:
node_modules/.bin/express -s -e -c css ./server
Otherwise it thought the server path was the type of css to use and was setting the code path to '.'

Resources