Typeerror cannot read property apply of undefined

It seems that the error happens at require(‘./routes/adminportal/home.js’)(app,passport);

Am I doing it wrongly ? I am following a tutorial on this website: https://scotch.io/tutorials/easy-node-authentication-setup-and-local

I am trying to do authentication on my website by using passport.js. Been struggling for hours to solve this. Any help will be appreciated. Thanks.

1 Answer 1

The home.js file you show exports a router. A router is not something you import like this:

If you look at the code for /app/routes.js in the tutorial you pointed to, the file that works with that type of import is shown there and it has an export like this:

So, you appear to have files mixed up when trying to follow that demo. You’re exporting a router, but attempting to call a function that should have been exported like the line above.

Since I can’t see the overall lay of the land in your code, all I can tell you is that when you export a router, you then use it like this this:

depending upon exactly what you’re trying to do. That’s how you hook a router into your web server.

пытаюсь стартануть сервер, но приложение крашится с такой ошибкой:
/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/compression-webpack-plugin/dist/index.js:175
compiler.hooks.emit.tapAsync(< name: ‘CompressionPlugin’ >, emit);
^

TypeError: Cannot read property ’emit’ of undefined
at CompressionPlugin.apply (/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/compression-webpack-plugin/dist/index.js:175:20)
at Compiler.apply (/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/tapable/lib/Tapable.js:375:16)
at webpack (/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/webpack/lib/webpack.js:33:19)
at Object. (/Users/orekhov.g/Documents/pantala/pantala-probe/server/index.js:19:22)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at loader (/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/babel-register/lib/node.js:154:7)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at Object. (/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/babel-cli/lib/_babel-node.js:154:22)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
[nodemon] app crashed — waiting for file changes before starting.

Читайте также:  Lmtools utility что это за программа

Пните меня в нужную сторону. Спасибо.

Comments

Copy link Quote reply

hutber commented Aug 10, 2016

I am on ubuntu 16.06 and have just done a fresh install of node v6 with nvm. I have then installed gulp globally: npm i gulp -g

Now when I try to run a simple gulp script I get the following error:

Maybe this is something I am doing wrong, I have had a look at gulpInst.start.apply(gulpInst, toRun); and gulpInst.start is undefined.

This comment has been minimized.

Copy link Quote reply

yairEO commented Jan 11, 2017 •

How did you solve it?

This comment has been minimized.

Copy link Quote reply

hutber commented Jan 12, 2017

I believe but can’t remember 100% that gulp is the wrong package, you want gulp-cli for using gulp in terminal/cmd

This comment has been minimized.

Copy link Quote reply

momocow commented Feb 26, 2018

I have also met with this error.

From the error log of OP, we can find that the error is generated from your global gulp executable.

Check you global gulp version if it is greater than or equal to the one on which your package depends (which is installed locally).

This comment has been minimized.

Copy link Quote reply

mylastore commented Jun 5, 2018

I have the same issue

TypeError: Cannot read property ‘apply’ of undefined at /usr/lib/nodejs/gulp/bin/gulp.js:132:20 at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9) at Function.Module.runMain (module.js:695:11) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3

I have those install and still can’t figure this out.
[11:59:52] Requiring external module babel-register [11:59:52] CLI version 3.9.1 [11:59:52] Local version 4.0.0

This comment has been minimized.

Copy link Quote reply

Читайте также:  Icq и mail агент в одном приложении

momocow commented Jun 6, 2018

It’s obviously to see the problem in your log.

You can read that your global gulp is v3.9.1 while you declare a development dependency with gulp 4.0.0 locally (in your package.json).

[11:59:52] CLI version 3.9.1
[11:59:52] Local version 4.0.0

Also take a look at the first line of the stacktrace.

TypeError: Cannot read property ‘apply’ of undefined
at /usr/lib/nodejs/gulp/bin/gulp.js:132:20

You can find out that the error is coming from your global gulp, which is v3.9.1, while your local gulpfile.js is written in v4.0.0 fashion. v3.9.1 to v4.0.0 is a major update, in semantic versioning which means its a backward incompatible update.

Try to update your global gulp with npm i -g gulp@4 .

Rate this post

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *