【发布时间】:2020-04-28 04:18:29
【问题描述】:
我正在尝试构建使用 Typescript 的 Next.js/React 应用程序的 docker 映像。
Typescript 已安装,我可以在没有 docker 的情况下在本地运行构建。
但是,随着 docker 映像的构建,我想到了以下几点:
Step 8/10 : RUN npm run build
---> Running in ee577c719739
> project@0.0.5 build /app
> next build
Creating an optimized production build...
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry
It looks like you're trying to use TypeScript but do not have the required package(s) installed.
Please install typescript by running:
npm install --save-dev typescript
If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files).
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project@0.0.5 build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project@0.0.5 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我已经安装了 Typescript。这让我很困惑。
我使用的 Docker 镜像如下所示:
FROM gcr.io/companyX/companyX-node-base:12-alpine
# Copy in the project files
COPY . .
# Clean
USER root
RUN rm -fr node_modules
ENV NODE_ENV=production
COPY package*.json ./
RUN npm install && \
npm cache clean --force
RUN npm run build
EXPOSE 3000
# Running the app
CMD [ "npm", "start" ]
【问题讨论】:
-
你的 package.json 文件中提到过?
-
我一直在尝试 npm install typescript --save,我认为它会将它添加到我的正常依赖项中,但我错了,它只是在 dev 依赖项上。所以谢谢老哥。手动将其添加到正常依赖项中并运行。 :)
-
@RebaiAhmed 就我而言,是的。但我仍然收到该错误消息。见stackoverflow.com/questions/65831617/…
标签: reactjs typescript docker next.js