Const {assign} = require('lodash'); Syntax error unexpected {


#1

Hi guys,

I am trying to use npm package ‘mollie-es6’ in Meteor but I am getting this error:

Error 1:

WebstormProjects/untitled6/.meteor/local/build/programs/server/packages/modules.js:987
const {assign} = require('lodash');
      ^

SyntaxError: Unexpected token {
    at Object.exports.runInThisContext (vm.js:53:16)
    at WebstormProjects/untitled6/.meteor/local/build/programs/server/boot.js:287:30
    at Array.forEach (native)
    at Function._.each._.forEach (.meteor/packages/meteor-tool/.1.4.1_2.1z11dsj++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 /WebstormProjects/untitled6/.meteor/local/build/programs/server/boot.js:128:5
Exited with code: 1
Your application is crashing. Waiting for file change.

Error 2:


/WebstormProjects/untitled6/.meteor/local/build/programs/server/packages/modules.js:1102
        for (let i = 0; i < payments.length; i++) {
             ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at Object.exports.runInThisContext (vm.js:53:16)
    at /WebstormProjects/untitled6/.meteor/local/build/programs/server/boot.js:287:30
    at Array.forEach (native)
    at Function._.each._.forEach /.meteor/packages/meteor-tool/.1.4.1_2.1z11dsj++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/WebstormProjects/untitled6/.meteor/local/build/programs/server/boot.js:128:5
Exited with code: 1
Your application is crashing. Waiting for file change.

Can anybody explain why this is errors are showing up in Meteor?

Using it directly in NodeJS it’s working perfectly.


#2

Is mollie-es6 an es6 transpiler ??? Is so it may conflicts with meteor’d build in transpiler.


#3

No, it’s a payment method api


#4

Is not valid Meteor 1.4 code anyway. (Seems to me, at least …)


#5

It’s an NPM package https://www.npmjs.com/package/mollie-es6.
I’m using this method:

    const amount = 10.00;
    const description = 'My first API payment';
    const redirectUrl = 'http://example.org/order/12345';
    try {
        const payment = yield mollie.payments.create(
            amount,
            description,
            redirectUrl
        );
        res.redirect(payment.getPaymentUrl());
    } catch (e) {
        // Handle error
    }

#6

Add npm to the meteor first with

meteor npm install mollie-es6

Then you have to import it

import {mollie} from ‘mllies-es6’; << not sure the path is ok.

But the errors shown seems to be transpiler problem to me.


#7

Correct way:

const assign = require('lodash/assign');