Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

weird error : import get from 'lodash.get'; #32

Closed
PManager1 opened this issue Oct 28, 2017 · 1 comment
Closed

weird error : import get from 'lodash.get'; #32

PManager1 opened this issue Oct 28, 2017 · 1 comment

Comments

@PManager1
Copy link

image

associate-current-user.js

import get from 'lodash.get';
import set from 'lodash.set';

const defaults = {
idField: '_id',
as: 'userId'
};

export default function (options = {}) {
return function (hook) {
if (hook.type !== 'before') {
throw new Error(The 'associateCurrentUser' hook should only be used as a 'before' hook.);
}

if (!hook.params.user) {
  if (!hook.params.provider) {
    return hook;
  }

  throw new Error('There is no current user to associate.');
}

options = Object.assign({}, defaults, hook.app.get('authentication'), options);

const id = get(hook.params.user, options.idField);

if (id === undefined) {
  throw new Error(`Current user is missing '${options.idField}' field.`);
}

function setId (obj) {
  set(obj, options.as, id);
}

// Handle arrays.
if (Array.isArray(hook.data)) {
  hook.data.forEach(setId);

// Handle single objects.
} else {
  setId(hook.data);
}

};
}

package .json

{
"name": "newapp",
"description": "",
"version": "0.0.0",
"homepage": "",
"main": "src",
"keywords": [
"feathers"
],
"author": {
"name": "jpca999",
"email": "[email protected]"
},
"contributors": [],
"bugs": {},
"directories": {
"lib": "src",
"test": "test/"
},
"engines": {
"node": ">= 6.0.0",
"yarn": ">= 0.18.0"
},
"scripts": {
"test": "npm run eslint && npm run mocha",
"eslint": "eslint src/. test/. --config .eslintrc.json",
"start": "node src/",
"mocha": "mocha test/ --recursive"
},
"dependencies": {
"body-parser": "^1.18.2",
"compression": "^1.7.1",
"cors": "^2.8.4",
"feathers": "^2.2.3",
"feathers-authentication": "^1.3.0",
"feathers-authentication-hooks": "^0.1.5",
"feathers-authentication-jwt": "^0.3.2",
"feathers-authentication-local": "^0.4.4",
"feathers-configuration": "^0.4.2",
"feathers-errors": "^2.9.2",
"feathers-hooks": "^2.1.1",
"feathers-hooks-common": "^3.10.0",
"feathers-mongodb": "^2.9.1",
"feathers-nedb": "^2.7.0",
"feathers-rest": "^1.8.0",
"feathers-socketio": "^2.0.0",
"helmet": "^3.9.0",
"lodash": "^4.17.4",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
"mongodb": "^2.2.33",
"nedb": "^1.8.0",
"serve-favicon": "^2.4.5",
"winston": "^2.4.0"
},
"devDependencies": {
"eslint": "^4.9.0",
"mocha": "^4.0.1",
"request": "^2.83.0",
"request-promise": "^4.2.2"
}
}

@daffl
Copy link
Member

daffl commented Oct 28, 2017

ES module syntax is not yet supported in Node. You have to either set up Babel or change the imports to

const get = require('lodash.get');
const set = require('lodash.set');

@daffl daffl closed this as completed Apr 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants