Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.88k stars 604 forks source link

Can'r resolve buffer #634

Open EugeneApprentice opened 2 years ago

EugeneApprentice commented 2 years ago

Just created a react app (CRA), imported xml2js, when compiling I do get this error

Compiled with problems:X

ERROR in ./node_modules/string_decoder/node_modules/safe-buffer/index.js 4:13-30

Module not found: Error: Can't resolve 'buffer' in '/Users/dev/projects/tmp/barebone-cra/node_modules/string_decoder/node_modules/safe-buffer'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
    - install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "buffer": false }

ERROR in ./node_modules/xml2js/lib/parser.js 38:17-47

Module not found: Error: Can't resolve 'timers' in '/Users/dev/projects/tmp/barebone-cra/node_modules/xml2js/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "timers": require.resolve("timers-browserify") }'
    - install 'timers-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "timers": false }

Any ideas how to bypass it?

Node: 16.13.1

ctrlmaniac commented 2 years ago

I'm having the same issue

levos-snr commented 2 years ago

have you tried "browser": { "buffer": false } in your package.json

pedrobmarin commented 2 years ago

I'm having a similar problem. For now I'm sticking with https://github.com/facebook/create-react-app/releases/tag/v4.0.3 that does not include webpack 5. As far as I investigated it, looks like the problem goes deep into some dependency (sax, maybe?). I guess react-app users can also try to resolve with some 3rd party lib like craco.