Module not found: Error: Can't resolve 'perf_hooks' in


After adding

import { storage } from '@forge/api';

to my App.js, I suddenly get the following error when running ‘npm run build’:

> react-scripts build

Creating an optimized production build...
Failed to compile.
Module not found: Error: Can't resolve 'perf_hooks' in ... node_modules/@forge/api/out/api

Module not found: Error: Can’t resolve ‘perf_hooks’ in … node_modules/@forge/api/out/api

When I comment out import { storage } from '@forge/api'; and run ‘npm run build’ again, then it completes successfully.

I deleted node_modules and re-ran ‘npm install’ but if I still try to use storage I get the perf_hooks error. How do I correct this?

Update: Downgrading forge/api from 2.15.0 to 2.11.1 made it go away.

Update: For my situation, it turns out that I was trying to use
import {storage} from '@forge/api'
from Custom UI and you can only use it directly in Forge using a Bridge
as per Storage API in Custom UI