bartoszgolebiowski / zod-csv

The library with utils function for validating csv content
MIT License
12 stars 0 forks source link

Module importing error in v0.0.8 #6

Open sakamossan opened 1 year ago

sakamossan commented 1 year ago

Hello. I encountered an issue when using version 0.0.8 where modules couldn't be loaded.

Error

$ npx jest --testPathPattern validator/spreadsheet
 FAIL  src/validator/spreadsheet.test.ts
  ● Test suite failed to run

    TypeError: Object prototype may only be an Object or null: undefined
        at setPrototypeOf (<anonymous>)

      1 | import { readFile } from 'node:fs/promises';
    > 2 | import * as zodCsv from 'zod-csv';
        | ^
      3 | import { areaSchema } from './spreadsheet';
      4 |
      5 | describe('areaSchema', () => {

      at f (node_modules/zod-csv/dist/zcsv.umd.cjs:6:1417)
      at node_modules/zod-csv/dist/zcsv.umd.cjs:6:1446
      at node_modules/zod-csv/dist/zcsv.umd.cjs:6:1640
      at W (node_modules/zod-csv/dist/zcsv.umd.cjs:6:2289)
      at $ (node_modules/zod-csv/dist/zcsv.umd.cjs:6:2421)
      at node_modules/zod-csv/dist/zcsv.umd.cjs:8:2686
      at node_modules/zod-csv/dist/zcsv.umd.cjs:8:2692
      at node_modules/zod-csv/dist/zcsv.umd.cjs:1:162
      at Object.<anonymous> (node_modules/zod-csv/dist/zcsv.umd.cjs:1:319)
      at Object.<anonymous> (src/validator/spreadsheet.test.ts:2:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.699 s
Ran all test suites matching /validator\/spreadsheet/i.

When I downgraded to version 0.0.7, the import worked without any issues. There might be an issue with the generated umd.cjs file.

Environment

$ node --version
v18.13.0
$ npx jest --version
29.6.2
$ npx tsc --version
Version 4.9.5
$ head ./tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "lib": ["ES2020", "DOM"],
    "noImplicitReturns": true,
    "noUnusedLocals": false,
    "baseUrl": "src",
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
$ sw_vers
ProductName:        macOS
ProductVersion:     13.5.2
BuildVersion:       22G91

その他

Though seemingly unrelated, there were warnings and 429 errors during the build process of version 0.0.8.

bartoszgolebiowski commented 11 months ago

Hello, this is very strange. You are using ESModule instead of commonjs, but "imported" commonjs. Can you provide me a repo with a reproduction? I will try to resolve it. @sakamossan

yovanoc commented 9 months ago

nextjs and other framework takes the main entry so this is why

sakamossan commented 9 months ago

Apologies for the delayed response. I have prepared a minimal code example to reproduce the issue in my environment.

Environment

Steps to reproduce

$ git clone git@gist.github.com:2128748b0da8e7b884413cfe8a001883.git repro-zodcsv
$ cd repro-zodcsv/
$ npm ci
$ npm test
$ npm test

> tryzodcsv@1.0.0 test
> node --experimental-vm-modules node_modules/.bin/jest

 FAIL  ./index.test.ts
  ● Test suite failed to run

    TypeError: Object prototype may only be an Object or null: undefined
        at setPrototypeOf (<anonymous>)

      at f (node_modules/zod-csv/dist/zcsv.js:204:10)
      at node_modules/zod-csv/dist/zcsv.js:207:7
      at node_modules/zod-csv/dist/zcsv.js:218:7
      at ne (node_modules/zod-csv/dist/zcsv.js:239:6)
      at $ (node_modules/zod-csv/dist/zcsv.js:248:18)
      at node_modules/zod-csv/dist/zcsv.js:385:60
      at node_modules/zod-csv/dist/zcsv.js:386:3

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.577 s
Ran all test suites.
(node:99050) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
$ node --version
v18.13.0

Location of the error

The error occurs in the following part of the code

  at f (node_modules/zod-csv/dist/zcsv.js:204:10)
    return function(c, h) {
      f(c, h);
      function p() {
        this.constructor = c;
      }
      c.prototype = h === null ? Object.create(h) : (p.prototype = h.prototype, new p());
    };

It seems like the issue might be related to the process of adding polyfills during transpilation.

Other issue

It seems that this issue might be encountering a similar error. a situation where the prototype, which should be null, is instead becoming undefined.

TypeError: Class extends value undefined is not a constructor or null

ffilipovicc98 commented 8 months ago

I encountered the same error as described in this thread.

@sakamossan Have you successfully integrated zod-csv into your project?

ffilipovicc98 commented 8 months ago

Update from my side: Downgrade to v0.0.7 worked for me. So issue is still relevant for v0.0.8.