Closed CarterLi closed 2 years ago
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.
const parse = require('csv-parse/lib/sync')
// Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/sync' is not defined by "exports" in package.json
const parse = require('csv-parse/sync')
parse( ... )
// TypeError: parse is not a function
@AdamGaskins Please refer to the CommonJS documentation of CSV parse.
The latest versions shall fix this problem. I have update the browser ESM documentation and a new webpack demo is now available in the repository.
Closing, feel free to re-open if the problem persist.
localhost link?
@CarterLi comment updated
Hi, I appreciate your help with this. 5.0.3 introduces the following deprecation warning: (tested against Node LTS)
(node:24719) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./browser/esm/" in the "exports" field module resolution of the package at [...] imported from [...] Update this package.json to use a subpath pattern like "./browser/esm/*".
Thanks for your help. but the latest change doesn't work well with TypeScript
Compiled with problems:
ERROR in src/views/data-manage/dictionary-manage/create-edit-modal/create-edit-modal.ts:1:35
TS2307: Cannot find module 'csv-parse/browser/esm/sync' or its corresponding type declarations.
> 1 | import { parse as csvParse } from 'csv-parse/browser/esm/sync';
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 | import { Form } from 'element-ui';
3 |
4 | import { DictionaryApi } from '@/apis';
Can be work around with:
declare module 'csv-parse/browser/esm/sync' {
export * from 'csv-parse/dist/esm/sync';
}
Why not export csv-parse/dist/*
directly?
Same issue as @CarterLi :/
Cannot get this to work with TS.
For what it's worth, would it be useful to add to the github workflows to check for typescript compilation errors?
@richardeschloss every package has a ./test/api.types.ts
and a ./test/api.types.sync.ts
test file.
This thread is not TypeScript related. Please open another issue of TS.
Does anyone still has issue with webpack and JavaScript or is that part now working (despite the ./browser/esm/*
deprecation warning)?
It should work with pure JavaScript + webpack. I'm closing this
One note to anyone still running into this: the documentation still says:
import {stringify} from 'csv-stringify/browser/esm/index.js';
// Or
import {stringify} from 'csv-stringify/browser/esm/sync.js';
...and including the .js
bit at the end will cause Webpack to complain in some cases, because package.json
exports it without the .js
suffix.
Please propose enhancements to our webpack demos if you believe we missed something: https://github.com/adaltas/node-csv/tree/master/demo
import { parse } from 'csv-parse/dist/esm/sync.js';
Just results in:
12:31:50 PM [vite] Internal server error: Missing "./dist/esm/sync.js" export in "csv-parse" package
It doesn't work :tm:
Describe the bug
csv-parse specifies
which is problematic. If I import
csv-parse
withresults in
which forces me installing the
stream
polyfillIf I import
csv-parse
withresults in
because
/dist/esm/sync
is not exportedTo Reproduce
import { parse as csvParse } from 'csv-parse/sync';
Additional context