rikhoffbauer / react-abac

Attribute Based Access Control for React
https://rik-hoffbauer.gitlab.io/npm/react-abac/
89 stars 16 forks source link

build error - next.js / react - typescript #1012

Open faheemfactor opened 1 year ago

faheemfactor commented 1 year ago

React or Next.js build gives error for custom implementation

To Reproduce Steps to reproduce the behavior:

  1. Go to create a next.js project with typescript

  2. implement custom implementation package.json : "react-abac": "^0.1.13", image

  3. run next build.

  4. See error Attempted import error: 'create' is not exported from 'react-abac' (imported as 'create'). image

faheemfactor commented 1 year ago

a temp fix for next.js

const reactAbac = dynamic(() => import('react-abac'), { ssr: false })
reactAbac.create
rikhoffbauer commented 1 year ago

@faheemfactor, thanks for your bug report, I hope to look at this issue ASAP I will keep you informed.

flymans commented 10 months ago

Any update? Temp fix is not working using import { useAbac } hook

kopach commented 9 months ago

while waiting for official fix - you can always patch dependency (either natively by package manager like PNPM https://pnpm.io/cli/patch or Yarn) or with 3rd party tools like https://www.npmjs.com/package/patch-package for NPM

And fix/patch itself is quite simple - you just have to rename file extension from .js to .cjs as suggested in error and update path for it in package.json. Here is full patch

diff --git a/dist/index.js b/dist/index.cjs
similarity index 100%
rename from dist/index.js
rename to dist/index.cjs
diff --git a/package.json b/package.json
index 2b58fe260d4d8e16d606036780afc2326f65e866..228dc0d62a68fd30a1489d8715ad922dae7dd3be 100644
--- a/package.json
+++ b/package.json
@@ -17,7 +17,7 @@
     },
     "license": "ISC",
     "author": "Rik Hoffbauer",
-    "main": "dist/index.js",
+    "main": "dist/index.cjs",
     "module": "dist/index.es.js",
     "jsnext:main": "dist/index.es.js",
     "type": "module",