FlowRouter.route('/', {
action() {
ReactLayout.render(App, {content: <LP />});
}
});
I followed https://kadira.io/academy/meteor-routing-guide/content/rendering-react-components guide for using Flow Router. However, I keep getting this error:
I don't understand why there is an unexpected token. Does anyone know?
/Users/GLu/Desktop/more2me/.meteor/local/build/programs/server/app/lib/router.js:11
ReactLayout.render(App, { content: <LP /> }); // 3
^
SyntaxError: Unexpected token <
at /Users/GLu/Desktop/more2me/.meteor/local/build/programs/server/boot.js:241:30
at Array.forEach (native)
at Function._.each._.forEach (/Users/GLu/.meteor/packages/meteor-tool/.1.1.10.1b51q9m++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
at /Users/GLu/Desktop/more2me/.meteor/local/build/programs/server/boot.js:137:5
Thanks so much in advance for any help.
Related
My Meteor project has the DASH SDK installed as an NPM package. The goal is to call the "funds" function in methods.js from fixtures.js whenever a transaction is received. The address and amount are console logging from fixtures.js correctly, but I am receiving an error regarding bindEnvironment due to fibers. It does not console log from methods.js.
fixtures.js
import { Meteor } from 'meteor/meteor';
Meteor.startup(() => {
const Dash = require("dash");
const mnemonic = 'fake fake fake fake fake fake fake fake fake fake fake fake';
const client = new Dash.Client({ network: "testnet", wallet: { mnemonic } });
async function listenUnconfirmedTransaction() {
const account = await client.wallet.getAccount();
console.log(account);
account.on('FETCHED/CONFIRMED_TRANSACTION', (data) => {
console.dir(data);
var amount = data.payload.transaction.outputs[0]._satoshis;
var address = data.payload.transaction.outputs[0].script.toAddress("testnet").toString();
console.log("Amount: " + amount + ", Address: " + address);
if (address) {
Meteor.call('funds', address, amount, (error) => { if (error) { console.log(error); }});
};
});
};
listenUnconfirmedTransaction();
}
methods.js
import { Meteor } from 'meteor/meteor';
Meteor.methods({
'funds': function (address, received) {
console.log("Address: " + address + ", Received: " + received);
}
});
I have looked into the bindEnvironment and wrapAsync for Meteor, but I am not understanding how I can use them in this situation. Please advise
EDIT
Error:
I20220918-19:58:40.577(-7)? Amount: 200000000, Address: yQKFphqFK7yWSCzxor9SthWwL9Z17u4TyJ
I20220918-19:58:40.624(-7)? error: Error syncing incoming transactions Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment. Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
I20220918-19:58:40.625(-7)? at Object.Meteor._nodeCodeMustBeInFiber (packages/meteor.js:1188:11)
I20220918-19:58:40.625(-7)? at Meteor.EnvironmentVariable.EVp.get (packages/meteor.js:1213:10)
I20220918-19:58:40.625(-7)? at Server.applyAsync (packages/ddp-server/livedata_server.js:1774:64)
I20220918-19:58:40.626(-7)? at Server.apply (packages/ddp-server/livedata_server.js:1739:26)
I20220918-19:58:40.626(-7)? at Server.call (packages/ddp-server/livedata_server.js:1721:17)
I20220918-19:58:40.626(-7)? at Account.<anonymous> (server/main.js:16:20)
I20220918-19:58:40.626(-7)? at Account.emit (events.js:400:28)
I20220918-19:58:40.626(-7)? at Account.emit (domain.js:475:12)
I20220918-19:58:40.626(-7)? at Storage.<anonymous> (/home/alexanderwshea/Meteor/dashreceiver/node_modules/#dashevo/wallet-lib/src/types/Account/Account.js:107:72)
I20220918-19:58:40.626(-7)? at Storage.emit (events.js:400:28)
I20220918-19:58:40.627(-7)? at Storage.emit (domain.js:475:12)
I20220918-19:58:40.627(-7)? at ChainStore.<anonymous> (/home/alexanderwshea/Meteor/dashreceiver/node_modules/#dashevo/wallet-lib/src/types/Storage/methods/createChainStore.js:21:14)
I20220918-19:58:40.628(-7)? at ChainStore.emit (events.js:400:28)
I20220918-19:58:40.628(-7)? at ChainStore.emit (domain.js:475:12)
I20220918-19:58:40.629(-7)? at ChainStore.considerTransaction (/home/alexanderwshea/Meteor/dashreceiver/node_modules/#dashevo/wallet-lib/src/types/ChainStore/methods/considerTransaction.js:92:10)
I20220918-19:58:40.630(-7)? at /home/alexanderwshea/Meteor/dashreceiver/node_modules/#dashevo/wallet-lib/src/types/Account/methods/importTransactions.js:31:46
W20220918-19:58:40.630(-7)? (STDERR) (node:2339) UnhandledPromiseRejectionWarning: Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
W20220918-19:58:40.631(-7)? (STDERR) at Object.Meteor._nodeCodeMustBeInFiber (packages/meteor.js:1188:11)
W20220918-19:58:40.632(-7)? (STDERR) at Meteor.EnvironmentVariable.EVp.get (packages/meteor.js:1213:10)
W20220918-19:58:40.632(-7)? (STDERR) at Server.applyAsync (packages/ddp-server/livedata_server.js:1774:64)
W20220918-19:58:40.632(-7)? (STDERR) at Server.apply (packages/ddp-server/livedata_server.js:1739:26)
W20220918-19:58:40.633(-7)? (STDERR) at Server.call (packages/ddp-server/livedata_server.js:1721:17)
W20220918-19:58:40.633(-7)? (STDERR) at Account.<anonymous> (server/main.js:16:20)
W20220918-19:58:40.633(-7)? (STDERR) at Account.emit (events.js:400:28)
W20220918-19:58:40.634(-7)? (STDERR) at Account.emit (domain.js:475:12)
W20220918-19:58:40.634(-7)? (STDERR) at Storage.<anonymous> (/home/alexanderwshea/Meteor/dashreceiver/node_modules/#dashevo/wallet-lib/src/types/Account/Account.js:107:72)
W20220918-19:58:40.634(-7)? (STDERR) at Storage.emit (events.js:400:28)
W20220918-19:58:40.635(-7)? (STDERR) at Storage.emit (domain.js:475:12)
W20220918-19:58:40.635(-7)? (STDERR) at ChainStore.<anonymous> (/home/alexanderwshea/Meteor/dashreceiver/node_modules/#dashevo/wallet-lib/src/types/Storage/methods/createChainStore.js:21:14)
W20220918-19:58:40.635(-7)? (STDERR) at ChainStore.emit (events.js:400:28)
W20220918-19:58:40.636(-7)? (STDERR) at ChainStore.emit (domain.js:475:12)
W20220918-19:58:40.636(-7)? (STDERR) at ChainStore.considerTransaction (/home/alexanderwshea/Meteor/dashreceiver/node_modules/#dashevo/wallet-lib/src/types/ChainStore/methods/considerTransaction.js:92:10)
W20220918-19:58:40.637(-7)? (STDERR) at /home/alexanderwshea/Meteor/dashreceiver/node_modules/#dashevo/wallet-lib/src/types/Account/methods/importTransactions.js:31:46
W20220918-19:58:40.637(-7)? (STDERR) (Use `node --trace-warnings ...` to show where the warning was created)
W20220918-19:58:40.637(-7)? (STDERR) (node:2339) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
W20220918-19:58:40.638(-7)? (STDERR) (node:2339) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Ok, if you run Meteor up to version 2.7.3 you need to wrap that(details further down).
2.8 is now in preparation and it makes the move from Fibers (still compatible with NodeJS 14 but not with Node 16) to async. I think async now works server side, just keep an eye on this: https://forums.meteor.com/t/eta-of-2-8-release/58720
Wrapping for Fibers. This is basically running async code as if it was synchronous.
const bound = Meteor.bindEnvironment(callback => callback())
bound(() => {
...your code goes here.
})
Need to know:
I'm using the latest version of meteor
I'm using the latest version of moment.js
This code is on the server side
var date = moment(new Date());
console.log(date.format("YYYY-MM-DD HH:mm:ss.SS"));
I end up with this error
SyncedCron: Exception "count daily parks per spot" ReferenceError: moment is not defined
at spotIDList.forEach (app/server/main.js:66:18)
at SynchronousCursor.forEach (packages/mongo/mongo_driver.js:1054:16)
at Cursor.(anonymous function) [as forEach] (packages/mongo/mongo_driver.js:876:44)
at Object.job (app/server/main.js:62:16)
at packages/percolate_synced-cron.js:242:26
at scheduleTimeout (packages/percolate_synced-cron.js:290:7)
at packages/percolate_synced-cron.js:338:42
at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1186:26)
at packages/meteor.js:502:25
at runWithEnvironment (packages/meteor.js:1238:24)
the snippet above comes from the following code
SyncedCron.add({
name: 'Simple Cron Function',
schedule: function(parser) {
// parser is a later.parse object
return parser.text('every 15 second');
},
job: function(intendedAt) {
var spotList = spots.find({});
spotList.forEach((spot) => {
var devaddr = `${spot.devaddr}`;
var date = moment(new Date());
console.log(date.format("YYYY-MM-DD HH:mm:ss.SS"));
var dailyVisitsCount = log.find(
{
devaddr : devaddr,
car : "1",
createdAt: {
$gte: date.format("YYYY-MM-DD HH:mm:ss.SS")
}
},
{
sort: {
createdAt:1
}
}
).count();
spots.update({devaddr : devaddr}, { $set: {numberOfParksToday: dailyVisitsCount } } , {multi: false}, function(err, res) {
if (err) throw err;
});
console.log("Daily Visits Count Updated to " + dailyVisitsCount);
});
}
});
Any insight to why this block of code is not working the way it should that would be appreciates.
I did find out that this problem occurred due to a bug in a previous release of meteor which has been fixed.
I'm just trying to get today's date in a format my DB accepts and use that to filter my results. alternative suggestions is also welcomed.
PS: Momnet.js works for me in different locations(client side code)
EDIT:
W20180312-08:03:15.324(-7)? (STDERR) app/server/main.js:1
W20180312-08:03:15.325(-7)? (STDERR) (function(Npm,Assets){(function(){import moment from 'moment'
W20180312-08:03:15.325(-7)? (STDERR) ^^^^^^
W20180312-08:03:15.325(-7)? (STDERR)
W20180312-08:03:15.325(-7)? (STDERR) SyntaxError: Unexpected reserved word
W20180312-08:03:15.326(-7)? (STDERR) at Object.exports.runInThisContext (vm.js:53:16)
W20180312-08:03:15.327(-7)? (STDERR) at /home/elder/Desktop/Recreation-of-ParkeyeDashboard/ParkeyeDashboard/.meteor/local/build/programs/server/boot.js:289:30
W20180312-08:03:15.327(-7)? (STDERR) at Array.forEach (native)
W20180312-08:03:15.329(-7)? (STDERR) at Function._.each._.forEach (/home/elder/.meteor/packages/meteor-tool/.1.4.2_3.14963jl++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20180312-08:03:15.330(-7)? (STDERR) at /home/elder/Desktop/Recreation-of-ParkeyeDashboard/ParkeyeDashboard/.meteor/local/build/programs/server/boot.js:128:5
W20180312-08:03:15.330(-7)? (STDERR) at /home/elder/Desktop/Recreation-of-ParkeyeDashboard/ParkeyeDashboard/.meteor/local/build/programs/server/boot.js:344:5
W20180312-08:03:15.330(-7)? (STDERR) at Function.run (/home/elder/Desktop/Recreation-of-ParkeyeDashboard/ParkeyeDashboard/.meteor/local/build/programs/server/profile.js:480:12)
W20180312-08:03:15.331(-7)? (STDERR) at /home/elder/Desktop/Recreation-of-ParkeyeDashboard/ParkeyeDashboard/.meteor/local/build/programs/server/boot.js:343:11
You need to install the moment.js package:
meteor npm i --save moment
Then at the top of your file you need to import moment:
import moment from 'moment'
Then to get the date in a format the DB will accept using moment just do:
var date = moment().toDate()
Using moment() creates a moment object of the current date/time. Running toDate() on it gives you the same date/time in a Date object.
I have a peice of code;
Router.configure({
layoutTemplate: 'master_layout'
});
Router.map(function(){
this.route('generatePDF', {
path: '/pdf',
where: 'server',
action: function() {
console.log(voters.findOne().fetch());
var voters = voters.find();
....
}
});
How can I use any given collection inside action of routes.
i get error as below;
W20160510-20:19:29.909(5.5)? (STDERR) TypeError: Cannot call method 'findOne' of undefined
W20160510-20:19:29.910(5.5)? (STDERR) at [object Object].action (lib/routes.js:40:29)
W20160510-20:19:29.910(5.5)? (STDERR) at boundNext (packages/iron_middleware-stack/lib/middleware_stack.js:251:1)
Try this:
action: function () {
this.render('someTemplate',{
data: function(){
return Voters.find()
}
});
}
You've got multiple errors in your code.
Firstly, voters is undefined in the console.log line (as your error log says).
Secondly, Voters.findOne() returns a single document (assuming you have a collection called Voters). You can't call fetch on a document.
You can call fetch on a cursor. For example, Voters.find().fetch() would be fine.
Hope that helps
Am using the forum in Paypal tutorial to test the IPN listener, when i click on submit a new tab is opened and it says:
Error: Cannot find module 'paypal-ipn' at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17) at Object.Npm.require (/Users/mazinalmaskari/Desktop/code/.meteor/local/build/programs/server/boot.js:150:18)
at Object.Meteor.npmRequire (packages/npm-container/index.js:2:1) at [object Object].route.action (server/routing.js:6:30) at boundNext (packages/iron_middleware-stack/lib/middleware_stack.js:251:1) at runWithEnvironment (packages/meteor/dynamics_nodejs.js:110:1)
Am not sure where the problem is exactly, I get 500 Internal Server Error in the ngrok when i click submit.
this is my IPN listener located in the server
Router.map(function () {
this.route('ipn', {
path: '/ipn',
where: 'server',
action: function() {
var ipn = Meteor.npmRequire("paypal-ipn");
var wrappedVerify = Async.wrap(ipn, "verify");
var request = this.request;
var verified;
if (request.method !== 'POST') {
this.next();
} else {
try {
verified = wrappedVerify(request.body, {"allow_sandbox" : true});
} catch (error) {
//do something with error
}
if (verified === "VERIFIED") {
var payment = request.body;
//do something with payment
Router.go('/upload');
}
this.next();
}
}
});
});
This is the form am using (from Paypal tutorial):
<form target="_new" method="post" action="https://ba13954b.ngrok.io/ipn">
<input type="hidden" name="SomePayPalVar" value="SomeValue1"/>
<input type="hidden" name="SomeOtherPPVar" value="SomeValue2"/>
<input type="submit"/>
Any idea what might be causing this problem?
Review the module as the error message indicate. But...
Try like this:
var ipn = Meteor.npmRequire('paypal-ipn');
Based on:
https://github.com/meteorhacks/npm
I test the code in meteor .There are some errors.
/server/lib/Test.js
Test = {
say:function(){
console.log("hello world");
}
}
/server/main.js
Meteor.startup(function(){
Test.say(); //work well
var path = Npm.require('path');
var base = path.resolve('.');
var n = Npm.require('child_process').fork(base+"/app/server/children.js");
n.on('message', function(m) {
console.log('PARENT got message:', m);
});
n.send({ hello: 'world' });
});
/server/children.js
process.on('message', function(m) {
Test.say(); //throw a error . The Test is undefined
console.log('CHILD got message:', m);
process.send({name:"ABC"});
});
process.send({ foo: 'bar' });
errors:
I20131223-16:34:44.717(8)? hello world
W20131223-16:34:44.784(8)? (STDERR) /home/ec/workspace/meteor/testChildrenProcess/.meteor/local/build/programs/server/app/server/children.js:2
W20131223-16:34:44.784(8)? (STDERR) Test.say();
W20131223-16:34:44.785(8)? (STDERR) ^
W20131223-16:34:44.785(8)? (STDERR) ReferenceError: Test is not defined
W20131223-16:34:44.787(8)? (STDERR) at process. (/home/ec/workspace/meteor/testChildrenProcess/.meteor/local/build/programs/server/app/server/children.js:2:3)
W20131223-16:34:44.788(8)? (STDERR) at process.EventEmitter.emit (events.js:98:17)
W20131223-16:34:44.788(8)? (STDERR) at handleMessage (child_process.js:318:10)
W20131223-16:34:44.788(8)? (STDERR) at Pipe.channel.onread (child_process.js:345:11)
The Test Object is undefined in "/app/server/children.js" bu it's normal in main.js.
Why? Have I forgotten anything? Any help is appreciated.
The variables are scoped. While in Meteor Test would be available to the other files in your meteor project they are not available to Npm modules/stuff required by Npm.require.
The children.js would be in a different namespace to your main.js file. To access the Test variable in it you would need to pass it a param or as a message.