Skip to content

ReferenceError: Buffer is not defined #99

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

Closed
otto2me opened this issue Feb 26, 2021 · 5 comments · Fixed by #104
Closed

ReferenceError: Buffer is not defined #99

otto2me opened this issue Feb 26, 2021 · 5 comments · Fixed by #104
Labels
bug Indicates a reported issue or malfunction that needs fixing.

Comments

@otto2me
Copy link

otto2me commented Feb 26, 2021

Hi,

I like to use jira.js and have addit it to my project. However, I run into problems when I try to login to jira, by getting the below buffer error:

error userlogin ReferenceError: Buffer is not defined
at Object.getAuthentication (index.js:35)
at Client. (index.js:172)
at step (index.js:55)
at Object.next (index.js:36)
at index.js:30
at new ZoneAwarePromise (zone-mix.js:913)
at push.32ji.__awaiter (index.js:26)
at Client.sendRequest (index.js:166)
at Myself. (myself.js:151)
at step (myself.js:44)

I setup my conection like this:

const jira = new Client({
  host: host,
  authentication: {
    basic: {
      username: username,
      password: password
    }
  }
});

return jira.myself.getCurrentUser()
.then((user) => {
   console.log('userlogin',user);
  return user;
})
.catch((err) => {
  console.log('error userlogin',err);
  this.logError(err);
  return err;
}); 

The issue seems to be in node_modules\jira.js\out\helpers\index.js where the buffer cannot be used:
return "Basic " + Buffer.from(username + ":" + (apiToken || password)).toString('base64');

Any idea what I can do?
Without success I tried inside polyfills.ts:
(window as any)['global'] = window;
global.Buffer = global.Buffer || require('buffer').Buffer;

thx

@MrRefactoring
Copy link
Owner

Hi @otto2me, are you running the application on Node.JS, or is it designed to work in a browser? If for NodeJS, please tell me the version.

@otto2me
Copy link
Author

otto2me commented Mar 1, 2021

Hi,

I try to use it with the latest electron package, my setup is:
Angular CLI: 10.2.3
Node: 12.20.1
OS: win32 ia32

@MrRefactoring
Copy link
Owner

Thanks! I will deploy the same environment and try to reproduce

@otto2me
Copy link
Author

otto2me commented Mar 2, 2021

Ok, using electron I have to setup inside electron/main.js the following:
mainWindow = new BrowserWindow({width: 800, height: 600, webPreferences:{nodeIntegration:true, enableRemoteModule:true}})

Now it works.

@MrRefactoring
Copy link
Owner

Seems to be a problem after all, since I had planned to support browsers. I looked at how it worked with angular and was pretty frustrated. So I plan to solve this problem after all

@MrRefactoring MrRefactoring added the bug Indicates a reported issue or malfunction that needs fixing. label Mar 2, 2021
@MrRefactoring MrRefactoring mentioned this issue Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates a reported issue or malfunction that needs fixing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants