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

Uncaught TypeError: (0 , _hashIt2.default) is not a function #344

Open
dcowan-e-courier opened this issue Aug 11, 2023 · 8 comments
Open

Comments

@dcowan-e-courier
Copy link

dcowan-e-courier commented Aug 11, 2023

When calling run getting this error. This is implementing the simple first example provided in the documentation in a react web app

fact.js:119 Uncaught TypeError: (0 , _hashIt2.default) is not a function
    at Function.hashFromObject (fact.js:119:1)
    at Fact.getCacheKey (fact.js:112:1)
    at Almanac._setFactValue (almanac.js:149:1)
    at Almanac._addConstantFact (almanac.js:136:1)
    at new Almanac (almanac.js:63:1)
    at Engine.run (engine.js:377:1)
@chris-pardy
Copy link
Collaborator

@dcowan-e-courier can you check which version of hash-it you have installed?

@siawyoung
Copy link

I'm seeing this error too. If it helps, I have the same code running successfully in a Node environment, but running it in a browser environment (Chrome) produces the above error. The exact version of hash-it on both environments:

hash-it@^6.0.0:
  version "6.0.0"
  resolved "https://registry.yarnpkg.com/hash-it/-/hash-it-6.0.0.tgz#188df5a8ca2f8e036690e35f2ef88bd9417ff334"
  integrity sha512-KHzmSFx1KwyMPw0kXeeUD752q/Kfbzhy6dAZrjXV9kAIXGqzGvv8vhkUqj+2MGZldTo0IBpw6v7iWE7uxsvH0w==

@siawyoung
Copy link

@dcowan-e-courier if it helps, I tried running this in a fresh NextJS environment (using create-next-app) instead of create-react-app. That works. My guess is it has something to do with the Webpack bundling in create-react-app and how it messes up default exports. I don't have time to explore this further but hopefully it unblocks you!

@chris-pardy
Copy link
Collaborator

@siawyoung @dcowan-e-courier this does seem to be related to the export mapping on the hash-it package and how something like webpack is resolving that.

@MohHamoud
Copy link

I am having the same error in an existing project, I reproduced the issue by creating a project using create-react-app as @siawyoung mentioned, is there a fast way to fix it?
I understand that create-next-app creates a next.js application, which I don't prefer doing.

@chris-pardy
Copy link
Collaborator

@MohHamoud I haven't reproduced this issue since it's more related to webpack than json-rules-engine but...

The issue is likely that the webpack version that create-react-app is using doesn't understand the export mapping in hash-it's package.json.

Option 1: Downgrade hash-it - depending on your package manager of choice you may be able to force the resolution of hash-it to an older version that doesn't have the export mapping.
Option 2: Upgrade webpack. I'm not sure which version of webpack create-react-app uses but the export mapping is a fairly new package.json feature so we older webpack versions may not support it. This will likely requiring ejecting.

Overall I'd probably go the Option 2 route. specifically because create-react-app is no longer supported by the react team. If you don't wish to go with one of the various react-ecosystem setups then you're best bet is likely a roll-your-own approach.

@MohHamoud
Copy link

MohHamoud commented Aug 31, 2023

@chris-pardy I cloned the project, then copied the src files to my project and "yarn add"-ed the required dependencies (including hash-it)
it worked fine, without specifying the version of the hash-it nor the webpack

@chris-pardy
Copy link
Collaborator

@MohHamoud this makes sense since we transform the source from modules to common / require. As part of that babel is doing a default import transformation. Then the webpack resolution is giving us the wrong version of the hash-it library.

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

No branches or pull requests

4 participants