web-dev-qa-db-ja.com

Dockerイメージのビルド時にTypeScriptが既にインストールされている場合、TypeScriptをインストールするように求められます

TypeScriptを使用するNext.js/ReactアプリケーションのDockerイメージを構築しようとしています。

TypeScriptがインストールされており、Dockerなしでローカルでビルドを実行できます。

ただし、Dockerイメージが構築されているため、次の点に到達しました。

Step 8/10 : RUN npm run build
 ---> Running in ee577c719739

> [email protected] 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! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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" ]
4

@Ahmed Rebaiのクレジット

TypeScriptをPackage.jsonファイルの依存関係に手動で追加する必要がありました。通常のnpmインストールでは、devに追加するだけです。

1