Module not found: Can't resolve 'perf_hooks' ReactJS

Viewed 5064

I'm working on reactjs (17.0.1) (node v15.11.0) with typescript and I'm getting this warning message, any idea how solve it ?

./node_modules/typescript/lib/typescript.js
Critical dependency: the request of a dependency is an expression

./node_modules/typescript/lib/typescript.js
Critical dependency: the request of a dependency is an expression

./node_modules/typescript/lib/typescript.js
Module not found: Can't resolve 'perf_hooks' in '/Users/jorge/Documents/Development/Projects/React-Js/project/node_modules/typescript/lib'

thanks in advance

3 Answers

As far as I can tell this is still an outstanding issue: https://github.com/microsoft/TypeScript/issues/39436

I get the exact same 3 warnings when I import anything from typescript - ex:

import { transpile } from 'typescript';

results in:

Compiled with warnings.

./node_modules/typescript/lib/typescript.js Critical dependency: the request of a dependency is an expression

./node_modules/typescript/lib/typescript.js Critical dependency: the request of a dependency is an expression

./node_modules/typescript/lib/typescript.js Module not found: Can't resolve 'perf_hooks' in 'C:\me\myName\GitHub\projectFolder\node_modules\typescript\lib'

I had this same error when working on a Next.JS application with only a frontend and added TS later. I believe it is to do with the NPM TypeScript Node package. I resolved it by running:

npm i typescript @types/react @types/node

to install all the TypeScipt dependencies (including for Node)

Check to see that your node version is up to date with node -v If it's not you can download the latest LTS at https://nodejs.org/en/download/

After download and installation verify that the latest version is now your default with node -v again. If you're unable to change your node version and have nvm (node version manager) installed you can select nvm alias default xx.xx.x (where xx.xx.x is the node version you wish to use as default).

Related