Cannot run Angular-cli at node 10.16.0 - node.js

Here is my computer information:
node version 10.16.0
npm version 6.9.0
Environment Variables C:\Users\tran.sonhoang\AppData\Roaming\npm\node_modules\#angular\cli\bin
My problem is when I run ng new app-name I will get the file with this info
#!/usr/bin/env node
'use strict';
// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
try {
process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
} catch(_) {
// If an error happened above, use the most basic title.
process.title = 'ng';
}
// Some older versions of Node do not support let or const.
var version = process.version.substr(1).split('.');
if (Number(version[0]) < 10 || (Number(version[0]) === 10 && Number(version[1]) < 9)) {
process.stderr.write(
'You are running version ' + process.version + ' of Node.js, which is not supported by Angular CLI 8.0+.\n' +
'The official Node.js version that is supported is 10.9 or greater.\n\n' +
'Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.\n'
);
process.exit(3);
}
require('../lib/init');
This issue is so strange to me since this is the first time I see this issue with angular-cli.
What I have tried:
Removed node and install again the same version.
Remove npm cache + update npm
Remove Angular-cli and re-install
But It still not fix this issue. Any help will be appreciated.Thanks!

Related

Use node ssh into Runcloud gives a different version to what is actually installed/used by NVM on the server

I have a server on Runcloud on which I've used NVM and installed the version 16.14.2.
If I ssh via any SSH client and run node -v, I effectively get 16.14.2
Though when I wrote a script to ssh into the server and run the same command, I get 10.0
I was previously advised to create an alias, I tried to follow some steps I came across for that but it did not fix my issue. Further more, referencing the path to the desired version of npm inside nvm gives me an error that this version npm cannot run with node 10.0
npm does not support Node.js v10.0.0\n
Below is my code
import { NodeSSH } from 'node-ssh'
const ssh = new NodeSSH()
const { environment } = await inquirer.prompt([
{
name: 'environment',
message: `Environment?`,
type: 'input',
default: 'development'
}
])
if (build) {
const sshConfig = sshConfigs[environment]
console.log(chalk.yellow(`Connecting to ${sshConfig.host}...`))
await ssh.connect(sshConfig)
console.log(chalk.green('Connected'))
console.log(chalk.yellow('Executing release...'))
const nodePath = '~/.nvm/versions/node/v16.14.2/bin/node'
const npmPath = '~/.nvm/versions/node/v16.14.2/bin/npm'
console.log(await ssh.execCommand(`${npmPath} -v`))
ssh.dispose()
console.log(chalk.green('Release completed'))
}

azure appservice not using correct version of NPM when using child process

I am trying to use child process in my dot net core application to run some npm and ng commands.
I have set WEBSITE_NODE_DEFAULT_VERSION =12.18.0 and WEBSITE_NPM_DEFAULT_VERSION=6.14.4 and in kudu powershell/cmd its showing correct version
D:\home>npm --version
6.14.4
D:\home>node -v
v12.18.0
My code in c# to run npm commands :
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = #"cmd.exe";
processInfo.ErrorDialog = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.RedirectStandardError = true;
processInfo.Arguments = $"/C npm -version";
Process process = Process.Start(processInfo);
process.WaitForExit();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
shows npm version as as 1.1.37 but it will display node version correclty if i use node -v as command.
Deploying from VS to AZURE
I hope some one has solution for my problem. Thank you

ng v is working in cmd but not working in vs code

SO i wanted to create an web application so i downloaded VS code and node.js the current version and i installed everything successfully.
When i type ng v in cmd i am able to view the version of angular but when i open a folder and run the same command in vs code i get an error code like this
#!/usr/bin/env node
'use strict';
// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
try {
process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
} catch(_) {
// If an error happened above, use the most basic title.
process.title = 'ng';
}
// Some older versions of Node do not support let or const.
var version = process.version.substr(1).split('.');
if (Number(version[0]) < 8 || (Number(version[0]) === 8 &&
Number(version[1]) < 9)) {
process.stderr.write(
'You are running version ' + process.version + ' of Node.js, which is not supported by Angular CLI v6.\n' +
'The official Node.js version that is supported is 8.9 and greater.\n\n' +
'Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.\n'
);
process.exit(3);
}
require('../lib/init');
i know this says node version is < 8 but my node version is 12.1.0 which is clearly greater than version 8. I even tried to uninstall it and reinstall it but still i am getting this error. PLEASE HELP MEE

Waiting on 1 test

I have the following test
// tests/CheckboxWithLabel-test.js
jest.dontMock('../test.js');
describe('CheckboxWithLabel', function() {
it('changes the text after click', function() {
var React = require('react/addons');
var CheckboxWithLabel = require('../test.js');
var TestUtils = React.addons.TestUtils;
// Render a checkbox with label in the document
var checkbox = TestUtils.renderIntoDocument(
<CheckboxWithLabel labelOn="On" labelOff="Off" />
);
// Verify that it's Off by default
var label = TestUtils.findRenderedDOMComponentWithTag(
checkbox, 'label');
expect(label.getDOMNode().textContent).toEqual('Off');
// Simulate a click and verify that it is now On
var input = TestUtils.findRenderedDOMComponentWithTag(
checkbox, 'input');
TestUtils.Simulate.change(input);
expect(label.getDOMNode().textContent).toEqual('On');
});
});
when I try to run it though using jest, I get the following error: Waiting on 1 test
I run npm test
What should I do?
You did not specify the version of Node you were using. Your problem could be because you are using a newer version of Node and Jest works with version 0.10.0. This is an open issue on Github (https://github.com/facebook/jest/issues/243)
To downgrade your version of node, use the n package as follows:
npm install -g n # Install n globally
n 0.10 # Installing the correct version of node
This can result in some weird problems with your current packages, so delete your node_modules folder and perform a clean install.

How do I require a minimum version of node.js in my script?

I just found out that a script I wrote only works on node 0.10 because it uses readable events.
How do I require a minimum version of node.js in my script so that users know that they need to upgrade?
In package.json:
{ "engines" : { "node" : ">=0.10.3" } }
From the docs.
Edit, a programmatic way:
var pkg = require('./pacakge'),
semver = require('semver');
if(!semver.satisfies(process.version, pkg.engines.node)) {
// Not sure if throw or process.exit is best.
throw new Error('Requires a node version matching ' + pkg.engines.node);
}
Add this to top the top of your script.
var versionComps = process.versions['node'].split('.');
if (parseInt(versionComps[0]) === 0 && parseInt(versionComps[1]) < 10) {
console.log('Script requires node.js version >= 0.10');
process.exit(1);
};

Resources