【发布时间】:2019-01-31 03:10:18
【问题描述】:
所以我有一个 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 编译时失败,输出项目中大多数文件的编译错误。
如果我在WORKDIR... 上方的Dockerfile 中设置ENV NODE_ENV production,我也可以在本地复制它。
因此,Typescript 或 react-scripts-ts 在 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"]
}
任何建议将不胜感激! :)
编辑:将 env var args 添加到 Dockerfile。为了简洁起见,它最初被忽略了,但它最终成为问题和解决方案的一部分
【问题讨论】:
-
您可能应该发布错误消息。源代码在 GitHub 上吗?我有一个 React TS 项目,您可以尝试部署并开始添加一些包以查看它是否/何时失败。 github.com/styfle/react-server-example-tsx
标签: typescript docker environment-variables create-react-app vercel