所以我有一个create-react-app-ts
应用程序,我想 Dockerize 并在 Zeit Now 上托管。
一切都在本地运行良好,运行yarn tsc
良好react-scripts-ts build
。
从以下 Dockerfile 创建 Docker 映像也很有效:
FROM mhart/alpine-node:10.9
WORKDIR /usr/src
ARG REACT_APP_API_ENDPOINT
ARG NODE_ENV
COPY yarn.lock package.json ./
RUN yarn
COPY . .
RUN yarn build && mv build /public
但是,当发布到 Now 时,构建脚本在 Typescript 编译时失败,输出项目中大多数文件的编译错误。
如果我ENV NODE_ENV production
在上面的 Dockerfile 中设置,我也可以在本地重现它WORKDIR...
。
react-scripts-ts
因此,Typescript 或NODE_ENV=production
. 我以前从未遇到过这个错误,也不知道如何调试它。在本地运行NODE_ENV=production tsc
或也可以正常工作。NODE_ENV=production react-scripts-ts build
我正在使用以下配置运行 Typescript v 3.0.1:
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "build/dist",
"module": "esnext",
"target": "es6",
"lib": ["es6", "dom", "esnext.asynciterable"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": true,
"strict": true
},
"exclude": ["node_modules", "build", "scripts", "acceptance-tests", "webpack", "jest", "src/setupTests.ts"]
}
任何建议将不胜感激!:)
编辑:向 Dockerfile 添加了 env var args。为了简洁起见,它最初被遗漏了,但它最终成为问题和解决方案的一部分