Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'service' of undefined #173

Closed
ansarizafar opened this Issue Apr 25, 2016 · 16 comments

Comments

Projects
None yet
4 participants
@ansarizafar
Copy link

ansarizafar commented Apr 25, 2016

I am getting this error

image

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 25, 2016

If you don't call app.listen you will have to call app.setup(server) manually after starting the server for the services setup to be called.

@ansarizafar

This comment has been minimized.

Copy link
Author

ansarizafar commented Apr 25, 2016

I am using the project generated by feathers-cli. app.listen is present in index.js.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 25, 2016

Then it should be called. What changes did you make so far? What versions did it install (npm ls --depth 0)?

@ansarizafar

This comment has been minimized.

Copy link
Author

ansarizafar commented Apr 25, 2016

@daffl Here is the code repo with feathers server and ionic app. https://github.com/ansarizafar/feathers-demo

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 26, 2016

I just tried it and got a module not found error in https://github.com/ansarizafar/feathers-demo/blob/master/server/src/app.js#L19. After commenting that section and the .use('/graphql') part out it looked like everything worked. Can you confirm you are still seeing the same problem after that? I also didn't check it on Linux yet which it seems you are using.

@ansarizafar

This comment has been minimized.

Copy link
Author

ansarizafar commented Apr 26, 2016

I confirm, yes I am still seeing the same problem. I tried everything from the documentation but I am unable to find any solution. I am using Ubuntu 14.4. Could you please check it on Linux. I am really stuck because of this issue.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 27, 2016

I also tried on Ubuntu and cannot reproduce either. We need a little more information:

  • What does running into npm ls --depth 0 in the server folder say
  • What version of Node and npm?
  • What are the exact steps to reproduce?
@ansarizafar

This comment has been minimized.

Copy link
Author

ansarizafar commented Apr 27, 2016

Its really strange. How are you testing login and which loginName/ password you are using?
What does running into npm ls --depth 0 in the server folder say?

zafar@home:~/officeware/server$ npm ls --depth 0
server@0.0.0 /home/zafar/officeware/server
├── babel@6.5.2
├── babel-polyfill@6.7.4
├── babel-preset-node5@11.0.2
├── babel-watch@2.0.2
├── body-parser@1.15.0
├── compression@1.6.1
├── cors@2.7.1
├── feathers@2.0.0
├── feathers-authentication@0.7.5
├── feathers-configuration@0.2.3
├── feathers-errors@2.1.0
├── feathers-hooks@1.5.2
├── feathers-mongoose@3.3.7
├── feathers-rest@1.2.5
├── feathers-socketio@1.3.4
├── graphql-tools@0.3.12
├── jshint@2.9.2
├── mocha@2.4.5
├── mongoose@4.4.13
├── passport@0.3.2
├── request@2.72.0
├── serve-favicon@2.3.0
└── winston@2.2.0

What version of Node and npm?
Node V5.7.0, npm v3.6.0

What are the exact steps to reproduce?

I have generated project with feathers-cli with mongodb. Added few fields in user model

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const loginMatch = [ /^[a-zA-Z0-9]{6,20}$/, 'Login name must be 6 to 20 characters long, and can contain A-Z, a-z and 0-9.'];
const passwordMatch = [ /^(?=.*[A-Z])(?=.*[0-9])(?=.{6,15}$)/, 'Password must be 6 to 15 characters long, and contain at least 1 uppercase letter and 1 digit.'];

const userSchema = new Schema({

  userName: { type: String, required: true, maxlength: 25 },
  role: { type: String, required: true, default: 'Customer' },
  belongTo: { type: Schema.Types.ObjectId, default: null },
  isActive: { type: Boolean, required: true, default: true },

  loginName: {type: String, required: true, unique: true},
  password: { type: String, required: true },

  createdAt: { type: Date, 'default': Date.now },
  updatedAt: { type: Date, 'default': Date.now }
});

const userModel = mongoose.model('user', userSchema);

module.exports = userModel;

Note: hasPassword hook is showing validation error If Match validater is used on password field. I had opened another issue about it.

I have changed usernameField on authentication service to loginName.

'use strict';

const path = require('path');
const serveStatic = require('feathers').static;
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const feathers = require('feathers');
const configuration = require('feathers-configuration');
const hooks = require('feathers-hooks');
const rest = require('feathers-rest');
const bodyParser = require('body-parser');
const socketio = require('feathers-socketio');
const authentication = require('feathers-authentication');

const middleware = require('./middleware');
const services = require('./services');
const startup = require('./startup');
//const apolloServer = require('./data/apolloserver');

const app = feathers();

app.configure(configuration(path.join(__dirname, '..')));

app.use(compress())
  .options('*', cors())
  .use(cors())
  .use(favicon(path.join(app.get('public'), 'favicon.ico')))
  .use('/', serveStatic(app.get('public')))
  .use(bodyParser.json())
  .use(bodyParser.urlencoded({ extended: true }))
  .configure(hooks())
  .configure(rest())
  .configure(socketio())
  .configure(authentication({local: {usernameField: "loginName"}}))
  .configure(services)
  //.use('/graphql', apolloServer())
  .configure(middleware);

startup(app);

module.exports = app;

I am using babel-preset-node5 and babel-watch to run the server. It was also not working before using preset and babel-watch.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 28, 2016

For reproducing I meant, does the error happen during startup when trying to authenticate or when doing something else? Also, if you generate a new application from scratch and don't change anything, are you seeing the same problem?

@ansarizafar

This comment has been minimized.

Copy link
Author

ansarizafar commented Apr 28, 2016

The error happen when trying to authenticate from feathers-client. Yes I see the same problem in new application also. This issue can be re -produced by following these steps.

  1. Clone this repo.
  2. Open terminal.
  3. cd server
  4. npm start
  5. open another terminal
  6. cd client
  7. ionic serve
  8. try to login and check server terminal for error. Loginname: jazilkhan, password: Abcd1234
@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 29, 2016

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Apr 29, 2016

I think we can close this.

@ekryski ekryski closed this Apr 29, 2016

@ansarizafar

This comment has been minimized.

Copy link
Author

ansarizafar commented Apr 29, 2016

@daffl @ekryski your solution didn't work. I have disabled authentication service generated by feathers-cli and configured authentication in app.js. Finally I am able to login successfully. Please investigate this issue.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 29, 2016

That's the same solution to the problem. The error happens when configuring authentication twice which we found out. The generated application also works. As much as we like to help out I don't think there is much more left to investigate for us.

@sunabozu

This comment has been minimized.

Copy link

sunabozu commented Nov 21, 2016

I confirm, the problem is caused by configuring the authentication plugin twice.
Though I could reproduce it only in rest calls. Socket-io client works fine.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Nov 21, 2016

This is now fixed with the new 1.0.0-beta version of auth. It will throw an error if you try to configure auth twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.