Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node js - Importing mssql module for use in an Angular 2 project errors : " Can't resolve 'dns' " and " Can't resolve 'dgram' "

I have rudimentary experience in both Angular 2 and NodeJS development. I apologize if this question is too simple of nature.

My goal is to create a web interface which connects to a SQL Server database. This app would enable the user to easily send queries to and receive results from the connected database from the app.

Searching for solutions, I decided to import mssql module into my mssql-connection.service.ts after installing via npm. I was planning to use it in the service either by using dependency injection or its regular syntax. However, I am experiencing error while compiling in each of those situations.

First, in trying to use the DI method by writing import { MSSQL } from 'mssql'; I get two duplicate error messages node_modules/@types/mssql/index"' has no exported member 'MSSQL'.

Second, in my attempt to remedy the situation as a response, I write import 'mssql';. Then I get a total of three error messages: I get two duplicate error messages Can't resolve 'dns' in '...\node_modules\tedious\lib' and an error message Can't resolve 'dgram' in '...\node_modules\tedious\lib' I have also tried using const sql = require('mssql'); but this would give me Cannot find name 'require'. error message, preceded by the previous error messages.

I am stumped and would like to know why this is happening! I would like to be able to use external modules freely. I have also tried npm install @types/mssql but to no avail. My node version is v6.9.5, and am using Angular 4.0.0. Please help!

Thank you in advance.

like image 786
Nathan Lee Avatar asked Apr 19 '17 05:04

Nathan Lee


1 Answers

I don't really think what you're trying to achieve here is makes any sense. Don't you think it would be an anti-pattern to use this in your Angular App? How exactly are you supposed to distribute this App and make it secure as well?

I would suggest you use mssql, in your NodeJS project. You can expose APIs from there that you'll hit from your Angular App. That's what is the purpose of a client after all.

Doing this will make your code more manageable, maintainable, and loosely coupled.

Hope this makes sense.

like image 169
SiddAjmera Avatar answered Nov 15 '22 01:11

SiddAjmera