Question

npm run build is failing due to typescript or lodash uncompatibility

typescript version: 4.5.2
lodash version: 4.17.21

npm run build
tsc && react-scripts build


node_modules/@types/lodash/common/object.d.ts:1026:46 - error TS1005: '?' expected.
1026         : K extends `${infer N extends number}` ? T[N] <br/>
                                                  ~
node_modules/@types/lodash/common/object.d.ts:1031:46 - error TS1005: '?' expected.
1031         : K extends `${infer N extends number}` ? T[N] <br/>
                                                  ~
node_modules/@types/lodash/common/object.d.ts:1041:46 - error TS1005: '?' expected.
1041         : K extends `${infer N extends number}` <br/>
                                                  ~


Found 3 errors.
 4  3479  4
1 Jan 1970

Solution

 4

Use lodash version 4.17.5 works for me.

I am using typescript version 4.6.4 and lodash version 4.17.5.

Uninstall the current version (4.17.6) and reinstall 4.17.5 version

npm uninstall @types/lodash

npm install @types/lodash@4.17.5

Then, the ng build should work

2024-06-28
HaiDang

Solution

 1

try this

"@types/lodash": "4.14.168"

Finally ,It works like a charm ( "typescript": "4.1.5")

2024-06-28
soufiane ELAMMARI

Solution

 0

Upgrade typescript to v5+. Apart from this, if you're using any bundlers (e.g., Rollup, Webpack), don't forget to upgrade their TypeScript-related packages as well. I had to upgrade rollup-plugin-ts.

2024-07-01
Samuel Sunny Wilson

Solution

 0

I faced the exact same issue.

Two problems I have:

  • Lodash below version 4.17.20 has a critical security issue. So, downgrading is not an option.
  • Also, I can't update typescript to version 5 because of some old modules in my project...

My solution (=compromise) was to update Typescript to version 4.7.4 and the error disappeared.

2024-07-02
Jason

Solution

 0

The solution which worked for him.

  1. typescript version at 4.7.2.
  2. Added new dependency of @types/lodash at 4.17.5 version.
2024-07-03
ankit giri