javascriptreactjstypescriptnpmlodash

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.

Solution

  • 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