npm run build failing because of TypeScript error in docker build

Viewed 2854
Failed to compile.

/app/node_modules/@ant-design/icons/lib/components/AntdIcon.d.ts
TypeScript error in /app/node_modules/@ant-design/icons/lib/components/AntdIcon.d.ts(2,13):
'=' expected.  TS1005

  1 | import * as React from 'react';
> 2 | import type { IconDefinition } from '@ant-design/icons-svg/lib/types';
  |             ^
  3 | import type { IconBaseProps } from './Icon';
  4 | import { getTwoToneColor, TwoToneColor, setTwoToneColor } from './twoTonePrimaryColor';
  5 | export interface AntdIconProps extends IconBaseProps {

my package.json

{
  "name": "web",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/react-native-fetch-blob": "^0.10.5",
    "@types/react-select": "^3.0.16",
    "@types/rn-fetch-blob": "^1.2.1",
    "antd": "^4.2.4",
    "common-tags": "^1.8.0",
    "lodash": "^4.17.19",
    "moment": "^2.26.0",
    "node-sass": "^4.13.1",
    "normalize.css": "^8.0.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-redux": "^7.2.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.4.1",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0",
    "rn-fetch-blob": "^0.12.0",
    "socket.io-client": "^2.3.0",
    "typescript": "~3.7.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "storybook": "start-storybook -p 9000 -c .storybook"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@storybook/addon-actions": "^5.3.18",
    "@storybook/addon-info": "^5.3.18",
    "@storybook/addon-knobs": "^5.3.18",
    "@storybook/addon-notes": "^5.3.18",
    "@storybook/addons": "^5.3.18",
    "@storybook/preset-create-react-app": "^2.1.2",
    "@storybook/react": "^5.3.18",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "@types/common-tags": "^1.8.0",
    "@types/jest": "^24.0.0",
    "@types/lodash": "^4.14.150",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.0",
    "@types/react-dom": "^16.9.0",
    "@types/react-redux": "^7.1.7",
    "@types/react-router-dom": "^5.1.4",
    "@types/redux": "^3.6.0",
    "@types/socket.io-client": "^1.4.32",
    "babel-loader": "8.1.0",
    "react-docgen-typescript-loader": "^3.7.2"
  }
}

My Dockerfile

FROM node:12 as builder

WORKDIR /app

COPY package.json .
RUN npm install
COPY . ./
RUN npm run build

FROM nginx:stable
COPY --from=builder /app/build /usr/share/nginx/html

After googling about the issue came to know https://github.com/ant-design/ant-design/issues/23266#issuecomment-613773502 you need update @types/react .I tried "@types/react" : "17.0.1". But didn't help.

1 Answers

Antd v4.2.4 uses TypeScript v3.9.2.

Feature import type which compiler complains is supported since TypeScript v3.8.

This feature is something most users may never have to think about; however, if you’ve hit issues under --isolatedModules, TypeScript’s transpileModule API, or Babel, this feature might be relevant.

import type { SomeThing } from "./some-module.js";
export type { SomeThing };

source: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html

Update your local TypeScript version from v3.7.2 to atleast v3.8.

Related