Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当节点_ENV=生产时,Typescript编译失败(在Docker中)_Typescript_Docker_Environment Variables_Create React App_Vercel - Fatal编程技术网

当节点_ENV=生产时,Typescript编译失败(在Docker中)

当节点_ENV=生产时,Typescript编译失败(在Docker中),typescript,docker,environment-variables,create-react-app,vercel,Typescript,Docker,Environment Variables,Create React App,Vercel,因此,我有一个createreact-app-ts应用程序,我现在想在Zeit上进行Dockerize和托管 本地一切正常,运行纱线tsc和反应脚本ts build效果很好 通过以下Docker文件创建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 .

因此,我有一个
createreact-app-ts
应用程序,我现在想在Zeit上进行Dockerize和托管

本地一切正常,运行
纱线tsc
反应脚本ts build
效果很好

通过以下Docker文件创建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
但是,发布到现在时,生成脚本在Typescript编译时失败,为项目中的大多数文件输出编译错误

如果我在我的Dockerfile中的
WORKDIR…
上方设置
ENV NODE\u ENV production
,我也可以在本地复制该数据

因此,当
NODE\u ENV=production
时,Typescript或
react scripts ts
的行为似乎有所不同。我以前从未遇到过这个错误,我不知道如何调试它。运行
NODE_ENV=production tsc
NODE_ENV=production resact脚本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。为了简洁起见,它最初被省略了,但它最终成为问题和解决方案的一部分

所以我终于找到了问题!在我原来的
Dockerfile
中,
NODE\u ENV
是在安装之前设置的。这意味着对于生产构建,
warn
不会安装
devdependency
,因此也不会安装任何我的
@类型
库。这导致了整个项目中所有的编译错误

节点的定义移动到
Dockerfile
中的
纱线安装后的下方,解决了该问题

FROM mhart/alpine-node:10.9
WORKDIR /usr/src

COPY yarn.lock package.json ./
RUN yarn

ARG REACT_APP_API_ENDPOINT
ARG NODE_ENV

COPY . .
RUN yarn build && mv build /public

注意:据我所知,
warn build
将确保再次删除
devDependencies
,因此不要担心会使您的构建膨胀。:)

您可能应该发布错误消息。源代码在GitHub上吗?我有一个React TS项目,您可以尝试部署并开始添加一些包,看看是否/何时失败。这让我头痛了好几个小时。谢谢