Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with adding tedious #4

Closed
ulou opened this issue Nov 5, 2020 · 3 comments
Closed

Problems with adding tedious #4

ulou opened this issue Nov 5, 2020 · 3 comments
Labels
question Further information is requested

Comments

@ulou
Copy link

ulou commented Nov 5, 2020

Hi!

Just installed dependency using yarn add tedious and yarn add @types/tedious , then tried to do simply connection, but looks like it's not possible cause I got following error:

Uncaught ReferenceError: require is not defined
    at Object.events (index.js:140122)
    at __webpack_require__ (index.js:790)
    at fn (index.js:101)
    at Object../node_modules/tedious/lib/bulk-load.js (index.js:99091)
    at __webpack_require__ (index.js:790)
    at fn (index.js:101)
    at Object../node_modules/tedious/lib/tedious.js (index.js:110052)
    at __webpack_require__ (index.js:790)
    at fn (index.js:101)
    at Module../src/app/database/sqlService.ts (index.js:139762)

looks like it comes from module.exports = require("events"); from tedious. There are a lot of answers in google about similar problems, that I should enable nodeIntegration. I don't think so thats it in this case, but anyway I've tried and it didn't work either.

Code:

export const connectToDb = (): Promise<Connection> => {
  return new Promise((resolve, reject) => {
    const config = {
      authentication: {
        options: {
          userName: "sa", // update me
          password: "" // update me
        },
        type: "default"
      },
      server: "test_gt_db@localhost", // update me
      options: {
        database: "test", //update me
        encrypt: true
      }
    }
    const connection = new Connection(config) // it breaks here
  })
} 
@codesbiome
Copy link
Owner

Hello ulou,

looks like it comes from module.exports = require("events"); from tedious. There are a lot of answers in google about similar problems, that I should enable nodeIntegration. I don't think so thats it in this case, but anyway I've tried and it didn't work either.

Can you try the same process with following WebPreference configuration in main.ts file for Electron Window.

    webPreferences: {
      nodeIntegration: true, // Changed 
      enableRemoteModule: false,
      contextIsolation: false, // Changed
      nodeIntegrationInWorker: false,
      nodeIntegrationInSubFrames: false,
      preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
    },

Following is the console.log output of Connection when having the configuration updated and using the source code you mentioned above:

image

Lemme know if you still face the same issue
Cheers!

@codesbiome codesbiome added the question Further information is requested label Nov 18, 2020
@ulou
Copy link
Author

ulou commented Nov 20, 2020

Hey @codesbiome,
thanks for the answer, I forgot to answer here. Your suggestion is correct, that's exactly how I fixed this.

My question and answer:
https://stackoverflow.com/questions/64706829/electron-tedious-requireevents-is-not-defined

@ulou ulou closed this as completed Nov 20, 2020
@codesbiome
Copy link
Owner

Hello @ulou

Good to know its working fine.
Thanks for confirmation,
Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants