'NODE_OPTIONS' is not recognized as an internal or external command - node.js

I'm on a windows 10 machine trying to run a build script from the git bash terminal.
On my terminal node is recognized just fine, for example I get the version when I run node --version.
But running the build script fails with the following error:
'NODE_OPTIONS' is not recognized as an internal or external command,
operable program or batch file.
I'm guessing I need to add something to my PATH variables to get this to work, but what?

Use cross-env package which easily sets environment variables.
Step 1:
Install cross-env from npm
npm i cross-env
In your package.json file (In this example your need is to run 'start' command which has 'NODE_OPTIONS')
{
"name": "your-app",
"version": "0.0.0",
"scripts": {
...
"start": "NODE_OPTIONS=<your options> <commands>",
}
}
Step 2
Add 'cross-env' in the script which you need to run NODE_OPTIONS. (In this case 'start' script)
{
"name": "your-app",
"version": "0.0.0",
"scripts": {
...
"start": "cross-env NODE_OPTIONS=<your options> <commands>",
}
}

For me installing the below mentioned package solved the problem
npm install -g win-node-env

Not a PATH issue, NODE_OPTIONS is an ENVIRONMENT VARIABLE that needs to be set before starting your build. To set en environment variable in Windows 10 you need to use the set command in a terminal mode. See this article on SUPERUSER forum to learn more.
In your case, just add set before NODE_OPTIONS and that will fix your issue.
Here's how to integrate it in package.json:
...
"scripts": {
...
"build": "set NODE_OPTIONS=--max_old_space_size=4096 && next build"
...
}
...

A way to launch both the node process and the debugger via F5, which does not require wrestling with env vars.
Make sure .vscode/launch.json is deleted.
1. Open the Run & Debug pane
2. Click on Node.js
3. DO NOT click on "Run script: dev" directly, instead click on the cog next to it
4. Your launch.json should look similar to:
{
"configurations": [
{
"type": "node-terminal",
"name": "Run Script: dev",
"request": "launch",
"command": "yarn run dev",
"cwd": "${workspaceFolder}"
}
]
}

Related

Volta with yarn run build system cannot find the path specified

This is the first time I'm using Volta, so bear with me.
I have installed globally typescript, node and yarn
yarn -v >> 1.22.10
node -v >> v14.15.4
npm -v >> 6.14.10
These commands work inside and outside my project folder, with the same results.
However if I use yarn build from inside vscode the output is an error stating:
System cannot find the path specified
If I do the same from outside vscode I get the same result:
If I go to the node_modules/.bin folder inside vscode, the command still doesn't work (this time I just only run tsc). The error is the following:
The term tsc is not a cmdlet recognized command, function, script file or executable program. Verify if the name is written correctly or, if there is an access route, verify the route is correct and try again.
But if the command is executed from outside vscode in a cmd window, it works as expected, because tsc is really there:
Additionally, if I run npm run build inside vscode, the command works as expected. This is my package.json:
{
"name": "socket-server",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"scripts": {
"build": "tsc",
"dev": "yarn build --watch --preserveWatchOutput",
"lint": "eslint src --ext js,ts",
"test": "jest"
},
"devDependencies": {
"eslint": "^7.19.0",
"jest": "^26.6.3",
"typescript": "^4.1.3"
},
"volta": {
"node": "14.15.4",
"yarn": "1.22.10"
}
}
I do suspect of volta because volta is managing yarn version, but no npm; but I don't really know what's the issue.
I'm using Windows and my PATH has the following entries:
What am I doing wrong?
Edit: Yes, Shell command shortcut exists:
the problem is about vsCode, you should run code . in cmd because if you Open the Command Palette (Ctrl + Shift + P) and type
Shell Command: Install 'code' command in PATH
you won't see noting, after running code . in cmd when you should see like this photo, every things will be fine
I’m not sure for Windows, but usually the scripts in node_modules/.bin are symbolic links to scripts. For instance, node_modules/.bin/tsc might point to node_modules/typescript/bin/tsc.
It works outside of the directory because then it uses the global version of tsc.
Seeing your error, I’m suspecting that the symlinks are broken. Maybe just try to remove node_modules directory and redo an npm install.
PS: I’m not familiar with Volta, but it looks more like an NPM problem.

Nothing happens when entering the babel command

I just installed babel as followed: npm install -g babel-cli
However when I try to enter the babel command in either nodejs cmd (as admin) or my editor pycharm's terminal, nothing happens.. It's like it's loading or something but even waiting for more than 20min. nothing appeares.
Screenshot
This started happening after I added C:\Users\sebas\PycharmProjects\storage\node_modules\.bin as a path to the environment variables
Before that, every time I tried running babel I would get a babel command not recognized as an external or internal command error.
What is going on?
In my opinion, the easiest way to solve this (see: not adding to your path) is to simply add an entry inside your package.json
For example:
...
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel src -d lib --copy-files",
},
...
This way, all you need to do is run npm run build, and it will take care of figuring out where babel is. Also, remember to add a .babelrc with the following content if you're using babel-preset-env:
{
"presets": ["env"]
}
More than likely because you have not added the .\node_modules\.bin directory to your path.
Until you do that, you can use .\node_modules\.bin\babel

my npm-lint is throwing error "missing script: lint"

I am trying to run npm run locally, and ran npm init, that created package.json. Here is my package.json
"name": "ironic-ui",
"version": "1.0.0",
"description": "======================== Team and repository tags ========================",
"main": "test-shim.js",
"directories": {
"doc": "doc"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.openstack.org/openstack/ironic-ui"
},
"author": "",
"license": "ISC"
}
Is there missing something? Or do i need to install something more? I am getting an error "Missing script: lint"
Thanks
You need to setup linter and add lint command in your package.json
Many linter are available. Assuming you setup eslint
https://www.npmjs.com/package/eslint
it would look something like this
// package.json
{
//...
"scripts": {
"lint": "eslint.js"
}
}
Add this script to your package.json file:
"lint": "./node_modules/.bin/eslint ."
Should not be removing eslint, instead should try to configure it to make it work to your preferences.
However, if you need to remove it because of time or other constraint
From firebase.json delete "npm --prefix \"$RESOURCE_DIR\" run lint"
From Package.json delete "lint": "eslint .", (should be within the scripts:)
Also from Package.json delete these devDependencies
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0"`
Delete this file from repo `.eslintrc.js
Then run npm i
then you should be able to run firebase deploy
I got the same problem.
I deleted functions folder, .firebaserc and firebase.json.
Then reinstalled firebase-tools
npm install -g firebase-tools
After firebase init, chose functions, it asked
Do you want to use ESLint to catch probable .....?.
I typed No.
It worked fine for me.
If you want to remove eslint from your Firebase Functions project, you can go to firebase.json and delete the line npm --prefix \"$RESOURCE_DIR\" run lint (inside predeploy). After this, you can delete the .eslintrc.json file inside your functions project
I ran into this issue when after setting up a firebase functions project inside a project that already had a firebase function elsewhere. It seems that firebase init doesn't necessarily know which project to set as "source" in firebase.json.
In my case, firebase.json simply pointed to the wrong source dir. I corrected it to point the my intended directory - issue solves.
Note: In my case, linting was desired, so removing linting was not the solution.
I get the exact same problem when I do:
firebase deploy --only functions
(-- only functions is optional), it redirects me to
npm --prefix %RESOURCE_DIR% run lint
It worked fine for me when I removed lint, thus having:
npm --prefix %RESOURCE_DIR% run
only.
For me i was just running the command without entering the function folder so it was not finding it i was just running this function on the project folder. So run cd function in your cmd if your are just in the project folder then run the command again but if the script is not in your package.json as mentioned above or you said no to eslint/lint when you initialized your firebase project lint wont work but others command that exist in your scripts work.
Editing package.json from "lint": "eslint .", to "lint": "eslint", worked for me.

Force node to use git bash on windows

I have a package.json file that looks like:
{
"name": "APP",
"version": "3.0.0",
"private": true,
"scripts": {
"start": "node app.js",
"test": "./test/dbLoad && env db=test test=1 jasmine"
}
}
When I run npm test, I get an error:
'.' is not recognized as an internal or external command
I'm guessing this is because node is using windows cmd.exe. The command works fine if i preface it with bash. Can I change a configuration setting of some kind in node so that it automatically uses bash?
Set NPM's script-shell to point to Git Bash (note the newer path):
npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe"
This tells NPM to run scripts defined in your package.json (such as start or test) using the specified shell instead of the default, which on Windows is cmd.exe. See https://docs.npmjs.com/misc/config#script-shell.
Yes you can!
Before running npm run you should do:
set comspec=your_bash.exe_folder
The NPM package, check the comspec enviroment, and run it on win32.
By default ComSpec=C:\windows\system32\cmd.exe
For more info you can see the source code of NPM: lifecycle.js (Line 219)
if (process.platform === 'win32') {
sh = process.env.comspec || 'cmd'
shFlag = '/d /s /c'
conf.windowsVerbatimArguments = true
}
You can set the environment comspec, to your bash by default by using the registry. If you need any help, please comment.

NODE_PATH not recognized

Here is my package.json script:
"scripts": {
"start": "NODE_PATH=$NODE_PATH:./shared node",
"dev": "npm run start & webpack-dev-server --progress --color"
},
When I run npm start in Windows 8 it shows the below error:
node_path is not recognized as a internal or external command, operable program or batch file
I had the same problem when I wanted to set the environment variable in a browserify script:
"scripts": {
"build:symlinked": "NODE_PATH=./node_modules browserify src/index.js > dist/build.js"
}
To be able to use linked node modules that are requiring peer-dependencies.
As mentioned above, you can try to set the environment variable manually or by script where it seems you have to use different commands depending on what command line tool you use.
For not having to do this every time, I found that npm package: cross-env.
By installing it and applying the script like this
"scripts": {
"build:symlinked": "cross-env NODE_PATH=./node_modules browserify src/index.js > dist/build.js"
}
I was able to solve that problem. This is mainly useful, if you work in a team with mixed MAC/Linux and Windows users, so you don't have to to take care about applying the Environment variables in such scripts anymore.
You don't need to define environment variable in package.json just use this
{
"scripts" : "node server.js"
}
or define what you want, here is the reference link.

Resources