dev-ip icon indicating copy to clipboard operation
dev-ip copied to clipboard

Return inside if block

Open OttlikG opened this issue 10 years ago • 4 comments

I use browser-sync which use your code as a dependency. When I transpile my code with babel6 a get this error: browser-sync/node_modules/dev-ip/lib/dev-ip.js: 'return' outside of function (41:8)

   39 |     var out = getIp();
   40 |     if (!out.length) {
 > 41 |         return console.log(messages.error);
      |         ^
   42 |     }
   43 |     console.log(getIp("cli"));
   44 | }

If I remove return from the 41th line, everything is ok. Could you verify my statement or fix this issue. Thans a lot.

OttlikG avatar Jan 04 '16 12:01 OttlikG

Why are compiling 3rd party code? You should be setting babel to ignore this surely?

shakyShane avatar Jan 04 '16 14:01 shakyShane

Still you shouldn't put a return if it's not in a function. Why not put an if () {} else {} instead?

mlagace avatar Aug 10 '16 00:08 mlagace

@OttlikG what did you do in the end? for k this library or find a way of ignoring it?

damiangreen avatar Dec 23 '21 11:12 damiangreen

If you're using Yarn 2+ you can fix the problem by doing the following:

  1. Add "dev-ip@^1.0.1": "patch:dev-ip@npm%3A1.0.1#./.yarn/patches/dev-ip-npm-1.0.1-6bbb9d1d09.patch" to the resolutions section of package.json
  2. Add dev-ip-npm-1.0.1-6bbb9d1d09.patch to ./yarn/patches
  3. Run yarn to update yarn.lock

Your build should now work.

cowwoc avatar Jan 24 '23 05:01 cowwoc