Skip to content

Commit

Permalink
feat: add buffer polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Mar 12, 2024
1 parent ba34ad6 commit bec86a9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/src/main.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('api', () => {
it('should work', () => {
expect(true).toBe(true)
})
})
1 change: 1 addition & 0 deletions web/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { StrictMode } from 'react'
import * as ReactDOM from 'react-dom/client'
import { BrowserRouter } from 'react-router-dom'
import './polyfill'

import { App } from './app/app'

Expand Down
6 changes: 6 additions & 0 deletions web/src/polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Polyfill the browser, prevents the error "Uncaught ReferenceError: Buffer is not defined"
if (typeof window !== 'undefined' && typeof window.global === 'undefined' && typeof Buffer === 'undefined') {
window['global'] = window
// eslint-disable-next-line @typescript-eslint/no-var-requires
global.Buffer = require('buffer').Buffer
}
1 change: 1 addition & 0 deletions web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = composePlugins(withNx(), withReact(), (config) => {
// e.g. `config.plugins.push(new MyPlugin())`
config.ignoreWarnings = [/Failed to parse source map/]
config.resolve.fallback = {
buffer: require.resolve('buffer/'),
crypto: false,
}
return config
Expand Down

0 comments on commit bec86a9

Please sign in to comment.