node-csv: csv-parse@5 is not usable with webpack@5 with esm syntax
Describe the bug
csv-parse specifies
{
"exports": {
".": {
"import": "./lib/index.js",
"require": "./dist/cjs/index.cjs"
},
"./sync": {
"import": "./lib/sync.js",
"require": "./dist/cjs/sync.cjs"
}
}
}
which is problematic. If I import csv-parse with
import { parse as csvParse } from 'csv-parse/sync';
results in
Module not found: Error: Can't resolve 'stream' in '/Users/carter/log-analysis/node_modules/.pnpm/csv-parse@5.0.1/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 }
which forces me installing the stream polyfill
If I import csv-parse with
import { parse as csvParse } from 'csv-parse/dist/esm/sync';
results in
Module not found: Error: Package path ./dist/esm/sync is not exported from package /Users/carter/log-analysis/node_modules/csv-parse (see exports field in /Users/carter/log-analysis/node_modules/csv-parse/package.json)
because /dist/esm/sync is not exported
To Reproduce
import { parse as csvParse } from 'csv-parse/sync';
Additional context
csv-parse@5.0.1
webpack@5.64.1
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 16 (7 by maintainers)
@AdamGaskins Please refer to the CommonJS documentation of CSV parse.
I’m having this exact problem, but in a nodejs app.
My node version is 16.13.0. I’m using require syntax instead of import above, but I’m getting similar error messages.
Does anyone still has issue with webpack and JavaScript or is that part now working (despite the
./browser/esm/*deprecation warning)?This thread is not TypeScript related. Please open another issue of TS.
Thanks for your help. but the latest change doesn’t work well with TypeScript
Can be work around with:
Why not export
csv-parse/dist/*directly?