S
S
Sergey Rybakov2017-06-09 20:49:40
MySQL
Sergey Rybakov, 2017-06-09 20:49:40

What causes Net.createConnection is not a function?

Hello, I recently started using NodeJS instead of PHP. And I started with AngularCLi (since AngularJS and MaterialAngularjs were used before), at the moment when I need to display data from the database, I get the error
"Uncaught TypeError: Net.createConnection is not a function"

The code
var mysql      = require('mysql');
//так же пробовал import * as mysql from 'mysql';

var connection = mysql.createConnection({
  host     : 'хост',
  database : 'база',
  user     : 'пользователь',
  password : 'пароль'
});

connection.connect();

connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
  if (err) throw err;
  console.log('The solution is: ', rows[0].solution);
  let Error = false;
});
connection.end();

в "typings.d.ts" так же пробовал ставить
declare var require: any;
declare var System: any;

Так же пробовал упороться и заменить все
var переменная = require('рейквайр');
в пакете mysql на
import * as переменная from 'реквайр';
Но выскакивает
Cannot assign to read only property 'exports' of object '[object Object]'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2017-06-09
@kyctarnik

https://stackoverflow.com/questions/38005968/error...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question