node-xml2js icon indicating copy to clipboard operation
node-xml2js copied to clipboard

Can'r resolve buffer

Open EugeneApprentice opened this issue 3 years ago • 3 comments

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

EugeneApprentice avatar Jan 08 '22 16:01 EugeneApprentice

I'm having the same issue

ctrlmaniac avatar Jan 16 '22 13:01 ctrlmaniac

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

levos-snr avatar Jan 16 '22 13:01 levos-snr

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.

pedrobmarin avatar Feb 01 '22 13:02 pedrobmarin