akveo / ngx-admin

Customizable admin dashboard template based on Angular 10+
https://akveo.github.io/ngx-admin/
MIT License
25.27k stars 7.96k forks source link

[Bug] Unable to launch json-server along with the app #844

Closed Deilan closed 5 years ago

Deilan commented 7 years ago

Pulled the latest version from your repo and installed json-server using npm install json-server. My intention is to launch json-server along with the app. The relevant lines of code for it goes to src/desktop.ts src/main.browser.ts src/main.browser.aot.ts and are executed just before the main bootstraper:

const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();

server.use(middlewares);
server.use(router);
server.listen(3001, function () {
  console.log('JSON Server is running');
});

The problem is that does not work.

In the webpack's output I am getting the following errors:

``` ERROR in ./~/json-server/lib/server/defaults.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\json-server\lib\server' @ ./~/json-server/lib/server/defaults.js 3:9-22 @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/errorhandler/index.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\errorhandler' @ ./~/errorhandler/index.js 19:9-22 @ ./~/json-server/lib/server/defaults.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/lodash-id/src/node.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\lodash-id\src' @ ./~/lodash-id/src/node.js 1:9-22 @ ./~/json-server/lib/server/router/index.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/express/lib/request.js Module not found:ERROR: Can't resolve 'net' in 'C:\Ekopoint\ng2-admin\node_modules\express\lib' @ ./~/express/lib/request.js 18:11-25 @ ./~/express/lib/express.js @ ./~/express/index.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/express/lib/view.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\express\lib' @ ./~/express/lib/view.js 18:9-22 @ ./~/express/lib/application.js @ ./~/express/lib/express.js @ ./~/express/index.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/send/index.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\send' @ ./~/send/index.js 24:9-22 @ ./~/express/lib/response.js @ ./~/express/lib/express.js @ ./~/express/index.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/graceful-fs/graceful-fs.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\graceful-fs' @ ./~/graceful-fs/graceful-fs.js 1:9-22 @ ./~/steno/index.js @ ./~/lowdb/lib/storages/file-async.js @ ./~/json-server/lib/server/router/index.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/etag/index.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\etag' @ ./~/etag/index.js 22:12-25 @ ./~/express/lib/utils.js @ ./~/express/lib/application.js @ ./~/express/lib/express.js @ ./~/express/index.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/graceful-fs/fs.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\graceful-fs' @ ./~/graceful-fs/fs.js 3:9-22 @ ./~/graceful-fs/graceful-fs.js @ ./~/steno/index.js @ ./~/lowdb/lib/storages/file-async.js @ ./~/json-server/lib/server/router/index.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/destroy/index.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\destroy' @ ./~/destroy/index.js 14:17-30 @ ./~/send/index.js @ ./~/express/lib/response.js @ ./~/express/lib/express.js @ ./~/express/index.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/mime/mime.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\mime' @ ./~/mime/mime.js 2:9-22 @ ./~/send/index.js @ ./~/express/lib/response.js @ ./~/express/lib/express.js @ ./~/express/index.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ERROR in ./~/jju/lib/utils.js Module not found:ERROR: Can't resolve 'fs' in 'C:\Ekopoint\ng2-admin\node_modules\jju\lib' @ ./~/jju/lib/utils.js 1:10-23 @ ./~/jju/index.js @ ./~/json-parse-helpfulerror/index.js @ ./~/lowdb/lib/storages/_json.js @ ./~/lowdb/lib/storages/file-async.js @ ./~/json-server/lib/server/router/index.js @ ./~/json-server/lib/server/index.js @ ./src/main.browser.ts @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts ```

and warnings:

``` WARNING in ./~/express/lib/view.js 80:29-41 Critical dependency: the request of a dependency is an expression WARNING in ./~/jju/lib/utils.js 8:2-3 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted ```

Targeting node in webpack config results in the absence of the errors above, but the warnings are still there and json-server still doesn't start.

nnixaa commented 7 years ago

Hey @Deilan, you need a separate backend app to launch the json-server.

Deilan commented 7 years ago

@nnixaa Thanks for the response! Could you kindly explain why I am ultimately need a separate app and can't launch it along with this app?