Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid invocation of hexoid in [email protected] #871

Closed
mwaibel-go opened this issue Jul 21, 2022 · 3 comments
Closed

Invalid invocation of hexoid in [email protected] #871

mwaibel-go opened this issue Jul 21, 2022 · 3 comments
Labels

Comments

@mwaibel-go
Copy link

mwaibel-go commented Jul 21, 2022

Support plan

  • Which support plan is this issue covered by? (Community, Sponsor, Enterprise): Community
  • Currently blocking your project/work? (yes/no): no
  • Affecting a production system? (yes/no): no

Context

  • Node.js version: v16.13.0
  • Release Line of Formidable (Legacy, Current, Next): Legacy
  • Formidable exact version: 2.0.1
  • Environment (node, browser, native, OS): node
  • Used with (popular names of modules): dependency of [email protected], which is a dependency of [email protected]. This issue appears to surface in other projects, as well.

What are you trying to achieve or the steps to reproduce?

I’m compiling a test suite with webpack. The tests require supertest, which through its dependency superagent relies on [email protected].

The offending lines are lines 8 and 15 in Formidable.js,

const hexoid = require('hexoid');
// ...
const toHexoId = hexoid(25);

You appear to be relying on hexoid’s behaviour prior to this commit in which the export mechanism was changed.

[Edit: It turns out I jumped to conclusions there, as the change in that repository was not published. I’m thinking this issue might actually be related to the switch to ES modules merged in 70517da (release 3.0.0), but JS modules are beyond me.]

Changing the import in line 8 to

const hexoid = require('hexoid').default;

fixes the error for me.

Unfortunately, the author of that library didn’t bump their version after the breaking change. I suggest you either released the fix I suggested above (if @^2.0.0 is still supported), or you pinned the exact git commit in your dependencies.

What was the result you got?

When I try to compile my tests using webpack, the compiler throws this Error:

TypeError: hexoid is not a function
    at Object../node_modules/formidable/src/Formidable.js ($PROJECT_DIR/dist/webpack:/$PROJECT_NAME/node_modules/formidable/src/Formidable.js:15:1)
    at __webpack_require__ ($PROJECT_DIR/dist/webpack:/$PROJECT_NAME/webpack/bootstrap:19:1)
    at Object../node_modules/formidable/src/index.js ($PROJECT_DIR/dist/webpack:/$PROJECT_NAME/node_modules/formidable/src/index.js:5:20)
    at __webpack_require__ ($PROJECT_DIR/dist/webpack:/$PROJECT_NAME/webpack/bootstrap:19:1)
    at Object../node_modules/superagent/lib/node/index.js ($PROJECT_DIR/dist/webpack:/$PROJECT_NAME/node_modules/superagent/lib/node/index.js:46:20)
    at __webpack_require__ ($PROJECT_DIR/dist/webpack:/$PROJECT_NAME/webpack/bootstrap:19:1)
    at Object../node_modules/supertest/lib/test.js ($PROJECT_DIR/dist/webpack:/$PROJECT_NAME/node_modules/supertest/lib/test.js:11:21)
    at __webpack_require__ ($PROJECT_DIR/dist/webpack:/$PROJECT_NAME/webpack/bootstrap:19:1)
    at Object../node_modules/supertest/index.js ($PROJECT_DIR/dist/webpack:/$PROJECT_NAME/node_modules/supertest/index.js:8:14)
    at __webpack_require__ ($PROJECT_DIR/dist/webpack:/$PROJECT_NAME/webpack/bootstrap:19:1)

($PROJECT_DIR and $PROJECT_NAME are replacements of my actual file path and project name.)

What result did you expect?

No compile-time error.

Thank you for your time.

@tunnckoCore
Copy link
Member

tunnckoCore commented Jul 23, 2022

Heya. @mwaibel-go

Yea, probably, that's why a massive ESM wave came last few years while I was absent. Finally we can write standard things and compile to whatever we what, properly.

I think we should support non-ESM (CJS) in v3, that's probably I'm holding moving v3 to latest (plus other stuff but yea). @GrosSacASac

const hexoid = require('hexoid').default;

Yea, that's an easy fix, I can patch it as 2.0.2 or something. Or you can PR, it's on v2-latest branch.

@bleistift-zwei
Copy link

Thank you for your response. I’ve looked into it, but on the v2-latest branch the test suite fails with a fresh clone. Applying the intended fix fails some 14 test cases more.

As I said, modules are really not my area of expertise, and currently I don’t have the time to read into that and another codebase to get the tests to work again. I’m sorry for that.

@GrosSacASac GrosSacASac closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2023
@angusryer
Copy link

angusryer commented Sep 1, 2023

For anyone coming to this with failures building using webpack or other build systems that use webpack under the hood, these threads have some successful fixes:

#337 (comment) (node, nextjs)
koajs/koa-body#224 (comment) (vue)

Haven't looking into it, but "webpack5 uses hexoid/dist/index.mjs by default while formidable uses it as a CommonJS module", as quoted by the second link's post author, seems correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants