I am trying to create an Angular application on a Windows 10 OS. Previously when I attempted to install Node.js and NPM I was getting 'Cannot find 'resolve' of undefined'. I solved it by downgrading my Node.js to 6.17 and the NPM to 3.10. I can now download the Angular CLI but when I use the 'new' command, I get the following error.
C:\Users\user_name\AppData\Roaming\npm\node_modules\#angular\cli\bin\ng:23
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:160:9)
When I open the file location I get the following:
#!/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';
}
// This node version check ensures that extremely old versions of node are not used.
// These may not support ES2015 features such as const/let/async/await/etc.
// These would then crash with a hard to diagnose error message.
// tslint:disable-next-line: no-var-keyword
var version = process.versions.node.split('.').map(part => Number(part));
if (version[0] < 10 || version[0] === 11 || (version[0] === 10 && version[1] < 13)) {
process.stderr.write(
'Node.js version ' + process.version + ' detected.\n' +
'The Angular CLI requires a minimum Node.js version of either v10.13 or v12.0.\n\n' +
'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
);
process.exit(3);
}
require('../lib/init');
It's complaining about the parentheses for the if statement. I tried getting rid of the parentheses and it only makes the situation worse. What would be the best way to go about solving this situation. WOuld it be better to use somehow install a new version of Node and work around the 'resolve' error or take with what I have with the version at hand?
Related
I am trying to use JSONStat toolkit for the first time. However I keep getting this error
let method = init.method || input.method || 'GET';
^
TypeError: Cannot read property 'method' of null
at new Request (/app/node_modules/node-fetch/lib/index.js:1217:21)
at /app/node_modules/node-fetch/lib/index.js:1439:19
at new Promise (<anonymous>)
at fetch (/app/node_modules/node-fetch/lib/index.js:1437:9)
at module.exports (/app/node_modules/jsonstat-toolkit/main.cjs:2:15410)
at Object.<anonymous> (/app/index.js:2:1)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
code when running:
const JSONstat = require("jsonstat-toolkit");
JSONstat( "https://json-stat.org/samples/oecd-canada-col.json" , function() {
if( this.class==="collection" ){
var ds1=this.Dataset( 0 );
}
} );
You are trying to use the syntax for the v0.x of JSONstat. The example clearly shows the correct use.
Change this to be a parameter that you accept as an argument to the function:
const JSONstat = require("jsonstat-toolkit");
JSONstat( "https://json-stat.org/samples/oecd-canada-col.json" , function(j) {
if( j.class==="collection" ){
var ds1=j.Dataset( 0 );
}
} );
Even with the correct code, version 1.4.1 seems to fail. Downgrading the package to 1.3.2 seems to fix it: npm i jsonstat-toolkit#1.3. UPDATE This has been fixed in 1.4.2 thanks to OP's bug report.
Alternatively, downgrade to version 0 and keep your same syntax (using this): npm un jsonstat-toolkit && npm i jsonstat.
Issued fixed in verison 1.4.2;
https://github.com/jsonstat/toolkit/issues/2#issuecomment-1079877683
I have 2 servers with exactly the same setup. But on 1 server I ran against an error and on another server it works well.
On server 1 :
[root#tst socketio]# npm list socket.io
/var/socketio
└── socket.io#2.0.4
Package nodejs-0.10.48-3.el6.x86_64 already installed and latest version
On server 2 :
[root#1 socketio]# npm list socket.io
/var/socketio
└── socket.io#2.0.4
Package nodejs-0.10.48-3.el6.x86_64 already installed and latest version
Script on server 1 :
[root#tst socketio]# node /var/socketio/socketioclient.js 1768
Time: 5/3/2018 21:10:6
ID: 1768
Start connect
S-connection
k95RAgJVnhzv4ItHABvu
S-emit event
S-disconnect
Script on server 2 :
[root#1 socketio]# node /var/socketio/socketioclient.js 1768
Time: 5/3/2018 20:59:24
ID: 1768
/var/socketio/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js:66
var headers = Object.assign({}, defaultHeaders);
^
TypeError: Object function Object() { [native code] } has no method 'assign'
at new XMLHttpRequest (/var/socketio/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js:66:24)
at /var/socketio/node_modules/socket.io-client/node_modules/engine.io-client/lib/transports/polling.js:24:13
at Object.<anonymous> (/var/socketio/node_modules/socket.io-client/node_modules/engine.io-client/lib/transports/polling.js:26:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/socketio/node_modules/socket.io-client/node_modules/engine.io-client/lib/transports/polling-xhr.js:6:15)
My socketioclient.js :
console.log(datetime);
console.log('ID: '+ID);
var io = require('socket.io-client');
console.log('Start connect');
var sSocket = io.connect('https://11.22.33.44:1234', {
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax : 5000,
reconnectionAttempts: 3
});
sSocket.on('connect', function (data) {
console.log('S-connection');
console.log(sSocket.id);
console.log('S-emit event');
sSocket.emit('event', { ID: ID });
sSocket.disconnect();
}
sSocket.on('serveroutput', function (data) {
console.log('S-serveroutput: '+data);
});
});
sSocket.on('disconnect', function (data) {
console.log('S-disconnect');
});
sSocket.on('reconnect', function() {
console.log('S-reconnecting');
});
sSocket.on('reconnect_failed', function (data) {
console.log('S-reconnect failed');
});
I see no difference in socketio version or in nodejs version. But the outcome is different. How come ?
I have read (on this website) about needing node version >= 4. But as it works on 1 server I don't think this is the issue here.
tl;dr Upgrade to the most recent Node LTS release (currently 8)
It looks like you have different versions of xmlhttprequest-ssl, even though the parent socket.io is at 2.0.4. xmlhttprequest-ssl version 1.5.4 or newer includes the use of Object.assign. Versions from 1.5.2 down might work better in Node 0.10.
If you look at the paths in the stack trace, there are a number of modules other than socket.io involved in the error:
socket.io-client/node_modules/engine.io-client/node_modules/xmlhttprequest-ssl
The npm command supported on Node 0.10 is non deterministic which means you can end up with two installs of the same parent module but they are made up from different child dependencies. This largely depends on when you ran the npm install as to what versions you get.
Recent versions of npm (5.x) and the yarn package manager now support lock files that fully describe an applications dependencies and will be able to create consistent installs over time.
A lot of modules have started dropping support for any Node versions prior to 4.x so this type of error is going to become more and more common for Node 0.x users.
Use the current Long Term Support release of Node. If you require packages for your RHEL platform, Nodesource provide rpms.
I deploy a node application to the Azure website.
The tricky part is that I'm using a node module called "opencv" that needs to be compiled at install time using node-gyp.
I use the node-gyp rebuild --arch=ia32 command to compile it int the windows10. But when I used it in the Azure website, I get following problem:
Wed Apr 26 2017 04:48:35 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:
Error: The specified module could not be found.
\\?\D:\home\site\wwwroot\app\api\lib\opencv.node
at Error (native)
at Object.Module._extensions..node (module.js:434:18)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (D:\home\site\wwwroot\app\api\lib\image_operation.js:5:14)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
This is the code I call:
'use strict';
var fs = require('fs');
var path = require('path');
var opencv = require("./opencv.node");
function isContains(str, substr) {
return new RegExp(substr).test(str);
}
module.exports = {
post: function (imageInfo, data) {
if (isContains(imageInfo.imageName, ".yuv")) {
var imageName = imageInfo.imageName.substr(0, imageInfo.imageName.length - 3) + "jpg";
opencv.yuvToJpeg(path.resolve(__dirname, "../../image/" + imageName), imageInfo.width, imageInfo.height, Array.prototype.slice.call(data, 0));
} else if (isContains(imageInfo.imageName, ".jpg")) {
fs.writeFileSync(path.resolve(__dirname, "../../image/" + imageInfo.imageName), data);
}
return "success";
}
};
But that file is in-fact deployed on the server:
Please help me, and tell me what to do
Its readme says that "You'll need OpenCV 2.3.1 or newer installed before installing node-opencv". And as Azure Web Apps is a Software as a service (SaaS), we don't have the privilege to install arbitrary software there. But if that is a requirement for you, you'll need to use an alternative offering, like Cloud Service or VM.
Gulp / npm noobie here.
I'm trying to use gulp-sourcemaps, and for some reason, it crashes on var sourcemaps = require('sourcemaps').(It crash only when this line's in the file)
gulpfile:
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('generateApp', function () {
return gulp.src([some paths...])
.pipe(sourcemaps.init())
.pipe(concat('app.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(path...));
});
Error :
C:\Projets\node_modules\strip-bom\index.js:2
module.exports = x => {
^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Projets\node_modules\gulp-sourcemaps\src\init.js:10:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Has anyone encounter this type of error?
I tried to google it, without any success.
I just started getting the same error and fixed it by replacing the code in C:\Projects\node_modules\strip-bom\index.js with this:
'use strict';
module.exports = function (x) {
if (typeof x !== 'string') {
throw new TypeError('Expected a string, got ' + typeof x);
}
// Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
// conversion translates it to FEFF (UTF-16 BOM)
if (x.charCodeAt(0) === 0xFEFF) {
return x.slice(1);
}
return x;
};
Then, I had to run npm rebuild node-sass to get it to work again. It seems to be an issue with an older version of the Strip-bom node module.
For more info, check this out: https://github.com/sindresorhus/strip-bom/commit/e2a3c3b83706ee5baac284f3862d3f6b9e1564e5
UPDATED ANSWER:
This error is caused by using an older version of Node. The Strip-bom module is now using ES2015 (ES6) syntax which requires Node 5.0+. (See Node's ES2015 support list here)
To test your version of Node, run:
node -v
If it's less than 5.0, you'll need to update it. You can download the newest version of Node here:
https://nodejs.org/en/
After installing the new version of Node, I still needed to run npm rebuild node-sass to get Gulp up and running again.
The former answer will still work if you don't want to update your Node version, however, as Louis pointed out, manually editing node module files is not a best-practice.
I am just trying to use Jest as unit testing framework.
I done and example from official ReactJS side.
function sum(value1, value2) {
return value1 + value2;
}
module.exports = sum;
----------------------------------------------------------------
jest.dontMock('../sum');
describe('sum', function() {
it('adds 1 + 2 to equal 3', function() {
var sum = require('../sum');
expect(sum(1, 2)).toBe(3);
});
});
But when I run npm tests I got next error:
/home/app.local/node_modules/jest-cli/bin/jest.js:12
const fs = require('fs');
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
npm ERR! Test failed. See above for more details.
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian
What is going wrong ?
If you read the documentation of the link that you posted, you can see that it says the following:
Jest uses ES2015 features and requires a Node.js version of at least 4.0.0 to run.
You are on version 0.10.25 which is probably why you are having issues. Upgrading your version to >= 4.0.0 should fix this.