React or Next.js build gives error for custom implementation
To Reproduce Steps to reproduce the behavior:
- Go to create a next.js project with typescript
- Write the following code:
import { create } from 'react-abac';
import { Permission } from './permissions';
import { Role } from './roles';
type User = {
id: string;
name: string;
rules: typeof Rules;
permissions: Permission|;
role: Role[];
}
export const {
AllowedTo,
secured,
NotAllowedTo,
AbacContextDefaults,
AbacProvider,
AbacContext,
useAbac,
} = create<Role, Permission, User>();
{
...
"dependencies": {
...
"react-abac": "^0.1.13",
...
},
...
}
- run next build.
- See error
ReferenceError: require is not defined in ES module scope, you can use import instead This file is being treated as an ES module because it has a 'js' file extension and '/src/node_modules/react-abac/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the 'cjs' file extension.
Attempted import error: 'create' is not exported from 'react-abac' (imported as 'create').
A temp fix for next.js:
const reactAbac = dynamic(() => import("react-abac"), { ssr: false });
reactAbac.create;
React or Next.js build gives error for custom implementation
To Reproduce Steps to reproduce the behavior:
{ ... "dependencies": { ... "react-abac": "^0.1.13", ... }, ... }Attempted import error: 'create' is not exported from 'react-abac' (imported as 'create').
A temp fix for next.js: