mafintosh / csv-parser

Streaming csv parser inspired by binary-csv that aims to be faster than everyone else
MIT License
1.41k stars 134 forks source link

Needs stream-browserify to work with Webpack 5 #183

Closed neoncube2 closed 3 years ago

neoncube2 commented 3 years ago

Webpack 5 was released a few days ago.

After upgrading, I'm getting this error:

Module not found: Error: Can't resolve 'stream' in 'C:\xampp\htdocs\mylittlewordland-frontend\src\.yarn\cache\csv-parse-npm-4.12.0-942560d935-ed6d90b1a6.zip\node_modules\csv-parse\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: { "stream": require.resolve("stream-browserify") }'
        - install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "stream": false }

Not sure what the best for csv-parser to fix this is, but I thought I'd mention it 🙂

neoncube2 commented 3 years ago

I think this is probably a signal what csv-parser may want to export different things for use with browsers vs. node.

Anyway, if anyone else is trying to get this to work with Webpack 5, here are the magic things that you need to put into webpack.config.js:

module.exports = {
resolve: {
            'stream': require.resolve('stream-browserify'),
            'events': require.resolve('events/')
        }
    },
plugins: [
        new webpack.ProvidePlugin({
            'Buffer': ['buffer', 'Buffer']
        }),
    ],
}

Then you also need to put stream-browserify, events, and buffer as dependencies in package.json

shellscape commented 3 years ago

Webpack 5 removes the node compatibility layer for browsers. Please read release notes for major versions. It's now on you to include that manually or implement the proper polyfills. It is not the responsibility of packages to provide browser compatibility