1

When I try to build my project it works but when it gets to the call for the database i get the error

./node_modules/msnodesqlv8/lib/sqlserver.native.js
module not found: Error: Can't resolve 'fs'

./node_modules/msnodesqlv8/lib/tableMgr.js
module not found: Error: Can't resolve 'fs'

Im not sure what the error is telling me i've tried reinstalling the package and clearing cache aswell as npm install what am i missing here

0

1 Answer 1

3

Node's built-in modules (such as path, fs and http) are only available in Node, not the browser. The msnodesqlv8 module makes use of fs, and most likely native code, so it too cannot run in the browser. This is one of the downsides of NPM being used for both back-end and front-end development - sometimes (especially for beginners) it's hard to tell which libraries work in which environments.

If you want to connect to a database from your front-end application, you have to expose it via HTTP - either by having a REST service of your own that delegates to the database, or potentially by using a database that has a REST service built-in.

Alternatively, if you don't need to make your data accessible from multiple machines, you can use some kind of browser-based storage to persist your data, such as localStorage or PouchDB. If you want to use SQL Server, though, you're going to have to take the REST route.

Sign up to request clarification or add additional context in comments.

6 Comments

So i cant use msnodesqlv8 then
What should I use instead of that in your opinion for connecting webserver to a local database @JoeClay
ive tried using MSSQL module but that errors saying cant resolve tls, net, dns, dgram
@andywilson: I've edited my answer to provide an alternative solution. Effectively, if you want to use a database, you need some kind of server component as well as your front-end React client. A simple Express server would suffice - in the Express application's code, you could then use msnodesqlv8 (or something similar) to connect to your database.
Thank you @JoeClay
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.