typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
73.01k stars 7.02k forks source link

Error declaring json-server inside a Karma/Mocha/Webpack test #308

Open OddEssay opened 8 years ago

OddEssay commented 8 years ago

I'm trying to spin up an instance of jsonServer inside a Mocha test, which I'm using with Webpack to build.

var jsonServer = require('json-server') alone causes the error, so I never get any further in configuration.

Running json-server from the command line works fine.

The full log of errors is:

... [snipped webpack build messages] ...
WARNING in ./~/express/lib/view.js
Critical dependencies:
78:29-56 the request of a dependency is an expression
 @ ./~/express/lib/view.js 78:29-56

WARNING in ./~/jju/lib/utils.js
Critical dependencies:
8:2-3 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/jju/lib/utils.js 8:2-3
14 06 2016 11:22:38.537:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
14 06 2016 11:22:38.546:INFO [launcher]: Starting browser Chrome
14 06 2016 11:22:38.579:INFO [launcher]: Starting browser Safari
14 06 2016 11:22:38.581:INFO [launcher]: Starting browser PhantomJS
14 06 2016 11:22:41.017:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#LTZGw0yufwv2hTJuAAAA with id 96503000
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  SyntaxError: Cannot declare a parameter named 'error' in strict mode
  at /Users/paul/Development/wizport/tests.webpack.js:44835
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 0 of 0 ERROR (0.54 secs / 0 secs)
14 06 2016 11:22:43.028:INFO [Chrome 45.0.2454 (Mac OS X 10.11.5)]: Connected on socket /#yS1ys8w0NpqrnCIYAAAC with id 81696188
14 06 2016 11:22:43.453:INFO [Safari 9.1.1 (Mac OS X 10.11.5)]: Connected on socket /#f4WRP35CtGV2mBr0AAAB with id 79571073
Safari 9.1.1 (Mac OS X 10.11.5) ERROR
  SyntaxError: Cannot declare a parameter named 'error' as it shadows the name of a strict mode function.
  at /Users/paul/Development/wizport/tests.webpack.js:44835
Safari 9.1.1 (Mac OS X 10.11.5): Executed 0 of 0 ERROR (0.654 secs / 0 secs)
Chrome 45.0.2454 (Mac OS X 10.11.5) ERROR
  Uncaught TypeError: Cannot read property 'prototype' of undefined
  at /Users/paul/Development/wizport/tests.webpack.js:51037
Chrome 45.0.2454 (Mac OS X 10.11.5): Executed 0 of 0 ERROR (1.966 secs / 0 secs)

Given just including the file causes the error, I'm not sure where to start in moving this along - Can anyone offer some suggestions?

Thanks in advance.

overthemike commented 7 years ago

I believe this issue is actually one of lowdb (a dependency of json-server) as I'm having the exact same issue when trying to run lowdb in an electron app using webpack.