feathersjs-ecosystem/errors

ReferenceError: Reflect is not defined

Closed this issue · 15 comments

I have strange error. When i try use any feathers errors my application is crashed.

Look at example:

var errors = require('feathers-errors')
var notFound = new errors.NotFound('User does not exist')
console.log(notFound)
» node test.js
/Users/kulakowka/Documents/node.js/sandbox/feathers-validate-hook/node_modules/feathers-errors/lib/index.js:21
    var instance = Reflect.construct(cls, Array.from(arguments));
                   ^

ReferenceError: Reflect is not defined
    at NotFound.ExtendableBuiltin (/Users/kulakowka/Documents/node.js/sandbox/feathers-validate-hook/node_modules/feathers-errors/lib/index.js:21:20)
    at NotFound.FeathersError (/Users/kulakowka/Documents/node.js/sandbox/feathers-validate-hook/node_modules/feathers-errors/lib/index.js:99:87)
    at new NotFound (/Users/kulakowka/Documents/node.js/sandbox/feathers-validate-hook/node_modules/feathers-errors/lib/index.js:187:77)
    at Object.<anonymous> (/Users/kulakowka/Documents/node.js/sandbox/feathers-validate-hook/lib/validate/index.js:6:16)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)

I have installed a latest version of feathers-errors.

@ekryski @daffl can you look this error? it is published to npm.

I think it's because we don't have this line in there:

if(!global._babelPolyfill) { require('babel-polyfill'); }

But I'll wait for @daffl to weigh in. He might have a better idea and I can't reproduce it.

I did not install babel globally. Perhaps this is the reason.

It seems not. I install babel as global, but it did not help.

daffl commented

Are you using Feathers v2? It loads the polyfill automatically.I started removing the auto imports from the other plugins so that we don't have to update everything all the time. We can add it back in if it is causing problems though.

I'm used it without feathers.

I experiment with my new hook: feathers-validate-hook.

Strangely, there are no more errors.

I am now currently receiving this error... should I open a new issue or should we reopen this one?

daffl commented

How are you using it? The Feathers main repository should load the Polyfill but if you are not including (which the error suggested) it you will have to add babel-polyfill yourself.

I was also getting this error, caught when I tried to authenticate in react native. I solved it by adding import core-js/fn/reflect in the top of the application.

The same error after updating react native to latest version (0.27.2). Requiring babel-polyfill fixed the problem.

Qard commented

I'm getting this in a react-native app. I'm guessing the polyfill doesn't get loaded when using feathers/client.

@Qard No I don't think it is getting loaded currently. I think @farwayer said you just need to require it. Give that a try and let us know if that worked. If so we'll look to document it or get it included or something.

daffl commented

I updated the docs to include babel-polyfill it a little while ago.

Just came across this problem using the latest versions of feathers on AWS Lambda (Node 4.3). Could fix it by adding

if(!global._babelPolyfill) { require('babel-polyfill'); }

To one of my .ts files. Apparently this solves the issue. Don't forget to npm install first.