Can't get Intern to run their own tutorial - intern

I'm new to NodeJS and even more for Intern trying to learn intern for testing at work but can't start intern-client by their own tutorial step-by-step, it is giving me back always the error:
C:\testproject\root>node ./node_modules/.bin/intern-client config=tests/intern
C:\testproject\root\node_modules\.bin\intern-client:2
basedir=`dirname "$0"`
^
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
I was following the Quick Start from their site https://github.com/theintern/intern and after creating the folders, installing intern through NodeJS and adding their example into the tests/folder. Running their script was not helpful to determinate what is wrong with their tutorial. Set the packages and non functional suites based on their example but still have no success.
//...
loader: {
// Packages that should be registered with the loader in each testing environment
packages: [ { name: 'root', location: '.' } ],
// map: { 'intern-selftest': { dojo: 'intern-selftest/node_modules/dojo' } }
},
// Non-functional test suite(s) to run in each browser
suites: [ 'root/tests/intern' ],
//...
I nuked the entire project several time, used jslint and jshint and got no syntax errors back.
Also tried some unsuccessful combinations with :
https: //github.com/theintern/intern-tutorial
https: //gist.github.com/neonstalwart/6630466
Any ideas or a REALLY working example available?
Thanks in advance.

Why are you putting node at the start of the command? None of the documentation says to do that. You’re trying to run a shell script with Node.js (which, to be clear, Intern did not create that shell script, your installer did), which will never work because JavaScript and sh are not the same language.

Related

How to accept Payments with Stripe

So this is my first time using Stripe to integrate payments for a website. What I am trying to do is add Stripe to my terminal for it to work correctly but I am getting an error. I have created a "Server" folder along with a "Server.js" file and when I try to initialize a new project it throws me an error.
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Royces-MacBook-Air:Kingdom Website roycewilliams$ $ cd server/
bash: $: command not found
Royces-MacBook-Air:Kingdom Website roycewilliams$ cd server/
Royces-MacBook-Air:server roycewilliams$ npm init -y
node:internal/modules/cjs/loader:926
throw err;
^
Error: Cannot find module './lib/_stream_readable.js'
Require stack:
- /usr/local/lib/node_modules/npm/node_modules/readable-stream/readable.js
- /usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/tracker-stream.js
- /usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/tracker-group.js
- /usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/index.js
- /usr/local/lib/node_modules/npm/node_modules/npmlog/log.js
- /usr/local/lib/node_modules/npm/lib/cli.js
- /usr/local/lib/node_modules/npm/bin/npm-cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:923:15)
at Function.Module._load (node:internal/modules/cjs/loader:768:27)
at Module.require (node:internal/modules/cjs/loader:995:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/readable-stream/readable.js:12:30)
at Module._compile (node:internal/modules/cjs/loader:1091:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:10)
at Module.load (node:internal/modules/cjs/loader:971:32)
at Function.Module._load (node:internal/modules/cjs/loader:812:14)
at Module.require (node:internal/modules/cjs/loader:995:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/lib/node_modules/npm/node_modules/readable-stream/readable.js',
'/usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/tracker-stream.js',
'/usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/tracker-group.js',
'/usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/index.js',
'/usr/local/lib/node_modules/npm/node_modules/npmlog/log.js',
'/usr/local/lib/node_modules/npm/lib/cli.js',
'/usr/local/lib/node_modules/npm/bin/npm-cli.js'
]
}
Royces-MacBook-Air:server royce
williams$
You probably just need to get the dependencies from npm. Type npm i in the same directory of the project to get the dependencies. If you don’t have npm installed you need to install it first.
Did you create this folder by yourself or did you clone/download it from one of Stripe's examples/repos?
If you downloaded it from somewhere, can you share the link?
Edit: The quickstart guide also has steps that you can follow to setup your integration

Deployement Nuxt.js ssr on passenger : SyntaxError: Cannot use import statement outside a module

I'm deploying my nuxt app on planethoster who use Passenger to run Node.js Application. I build the app by using ">npm run build" and deployed the content off .nuxt folder on the server, with "server.js" as entrypoint. but I ran on the following error:
/home/scalcmjx/test.scalomhouseplans.com/server.js:1
import Vue from 'vue'
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at Module.require (/opt/cpanel/ea-ruby27/root/usr/share/passenger/helper-scripts/node-loader.js:80:25)
at require (internal/modules/cjs/helpers.js:74:18)
at loadApplication (/opt/cpanel/ea-ruby27/root/usr/share/passenger/helper-scripts/node-loader.js:243:2)
at setupEnvironment (/opt/cpanel/ea-ruby27/root/usr/share/passenger/helper-scripts/node-loader.js:214:2)
Please Someone know how to manage it?
What is your node.js version? Try using the current LTS: 14.17.0
If I'm not mistaken, the import syntax is officially supported since v14, so this should maybe fix one issue.
Also, you need to deploy dist and not .nuxt, the latter is used for caching purposes.
I'm not sure of what is the process for this specific host, but you should probably get some decent ideas from the deployment section of the official documentation: https://nuxtjs.org/docs/2.x/deployment/deploying-to-21yunbox
There are a lot of hosting solutions there, one is probably looking like Planethoster.

Socket.io Syntax not Recognized on Server

Node server not able to understand socket.io syntax, even with all packages installed.
When I run my server locally with nodejs server.js it works fine is working. But, when I try to run it on my Ubuntu server, it does not seem to understand this line:
socket.on( 'client-data', ( serverpackage ) => {
^
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
The directory on my Ubuntu server is user/server, which contains all my server modules. Socket.io is installed, and I even checked to make sure all dependencies for socket.io are there too.
NodeJS-Socket-server-with-DB#1.0.0 /home/<user>/server
└── socket.io#2.1.1
I am also running this version of nodejs:
<user>#host*****:~/server$ nodejs -v
v0.10.25
You can't use arrow functions. You need at minimum version 4 of node however version 6 offers full compatability with arrow functions.
To fix your issue simply update node or change to a regular function like:
socket.on( 'client-data', function (serverpackage) {
Your nodejs version don't understand arrow function, check update if you want use it.
If not, please change arrow function to normal function.
Check Node.js ES2015 Support.

Deploy Utility app as Windows Service NodeJS

Working on deploying an app with PKG for Windows as a service via Node-Windows.
I have my NodeWindows install and uninstall scripts, and I'm trying to use PKG to make those into Windows executables. PKG creates the .exe files, but when I run the file, it throws an error like the one below:
pkg/prelude/bootstrap.js:1226
return wrapper.apply(this.exports, args);
^
ReferenceError: svc is not defined
at Object.<anonymous> (C:\snapshot\transient\installTransient2.js:0)
at Module._compile (pkg/prelude/bootstrap.js:1226:22)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (pkg/prelude/bootstrap.js:1281:12)
at run (bootstrap_node.js:432:7)
at startup (bootstrap_node.js:192:9)
at bootstrap_node.js:547:3
with my Node-windows script like this:
var Service = require('node-windows').Service;
var scv = new Service({
name: 'Transient2',
description: 'Yet Another File Transfer Utility in NodeJS',
script: 'server.js'
});
svc.on('install', () => {
console.log('successfully installed');
svc.start();
});
svc.install();
I want to think that node-windows isn't getting packed into the Executable. According to PKG's documentation, it should "shim" in anything in a require statement, unless it's declared with a path.join() call.
How can I package my app in an installer that creates a service in windows?
The hint is in the error - you have declared the variable name 'scv' instead of 'svc' on line 3 in your Node.js script.
This means that when you add the 'install' event handler on line 9 to 'svc' it cannot find that variable because it was misspelt. This is why you're receiving the ReferenceError described.

TypeScript external node modules sometimes transpile to module.exports and exports

I'm in the process of converting my node app to use TypeScript external modules. Everything works fine when running the app but when converting some of my .ts files, the mocha tests "explode" due to SyntaxError: Unexpected reserved word.
After much debugging, I've found the following reproducible failure case. I have a simple autoRoles.ts file that defines the available user roles. Prior to using external modules, it looked like:
/// <reference path="../../typings/backend_typings.d.ts" />
module.exports.roles = {
// role definitions
}
Now after the conversion:
/// <reference path="../../typings/backend_typings.d.ts" />
export let roles = {
// role definitions
}
When running the mocha tests, it generates the following error:
>> Mocha exploded!
>> SyntaxError: Unexpected reserved word
>> at exports.runInThisContext (vm.js:53:16)
>> at Module._compile (module.js:413:25)
>> at Object.Module._extensions..js (module.js:452:10)
>> at Module.load (module.js:355:32)
>> at Function.Module._load (module.js:310:12)
>> at Module.require (module.js:365:17)
>> at require (module.js:384:17)
>> at Object.<anonymous> (/Users/abc/esupport/code/asp_v4/lib/models/userRole.ts:77:17)
>> at Module._compile (module.js:434:26)
>> at Object.Module._extensions..js (module.js:452:10)
>> at Module.load (module.js:355:32)
>> at Function.Module._load (module.js:310:12)
>> at Module.require (module.js:365:17)
>> at require (module.js:384:17)
>> at Object.<anonymous> (/Users/abc/esupport/code/asp_v4/lib/users/lib/ssoAuth.ts:7:17)
>> at Module._compile (module.js:434:26)
>> at Object.Module._extensions..js (module.js:452:10)
>> at Module.load (module.js:355:32)
>> at Function.Module._load (module.js:310:12)
>> at Module.require (module.js:365:17)
>> at require (module.js:384:17)
>> at Object.<anonymous> (/Users/abc/esupport/code/asp_v4/lib/users/index.ts:5:31)
I can flip between the old implementation and the new implementation for the autoRoles.ts file and get mocha to pass and fall, respectively. Note, there is a require('<path>/autoRoles') on line 77 of userRoles.ts.
When comparing between the transpiled versions, the only difference is that the old version uses 'module.exports' and the new one just has 'exports'.
Old:
/// <reference path="../../typings/backend_typings.d.ts" />
exports.roles = {
// role definitions
}
New:
/// <reference path="../../typings/backend_typings.d.ts" />
module.exports.roles = {
// role definitions
}
So I'm aware that "exports" is just a shortcut to "module.exports" so I can't explain why this is causing mocha to fail but I do know that if I switch between the two and change nothing else, mocha "explodes". I've also noticed that for other transpiled modules, tsc sometimes uses "module.exports" and sometimes uses "exports". Why the difference and more importantly, why is mocha exploding?
Unexpected reserved word
Have "use strict"; at the top of your file. You probably have a variable that is a reserved keyword. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#Paving_the_way_for_future_ECMAScript_versions . TypeScript will warn on such variable names if you have that header in the file.
module.exports.roles = { is not the source of your error.
I've also noticed that for other transpiled modules, tsc sometimes uses "module.exports" and sometimes uses "exports".
Its similar to the nodejs convention. Basically saving characters (bytes) the runtime needs to parse.
export let foo = 123;
Will give you
exports.foo = 123;
(because exports == module.export therefore exports.foo == module.export.foo ... as you already know). However in :
let foo = 123;
export = foo;
It does
var foo = 123;
module.exports = foo;
Because if you reassign exports i.e. exports = foo then module.export !== exports. So you can use exports for extension .... but not assignment.
After more debugging, I found that mocha wasn't using the generated .js source code files that tsc transpiled. I'm not sure exactly how but it was trying to execute the "export var roles" located in the .ts file and "export" is a reserved word.
I came across this post, which indicated to me that mocha is trying to do it's own transpiling. That guy suggested to use "typescript-require" but that package looks like in the middle of being deprecated in favor of "ts-node". So I changed my grunt-ts config to look like:
mochaTest: {
test: {
options: {
reporter: 'spec',
require: [
'ts-node/register'
]
},
src: ['lib/test/**/*.spec.js']
}
},
This works but I'd be more than happy to have someone shed some light on what mocha was doing. Also, why was mocha successfully transpiling / not detecting "reserved word" in other .ts files that used export?
Edit 10/30/2015:
So I found out why mocha was trying to execute my .ts files. I was stupidly importing some of them as require('/path/file.ts') where I should have left the '.ts' extension off. I no longer need 'ts-node' in my mocha runner. This also explains why mocha was only erroring on some of my .ts files.

Resources