1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

docker buildで「It looks like you're trying to use TypeScript but do not have the required package(s) installed.」というエラーが出る

Posted at

Reactアプリをdockerでbuildしようと思ったら、下記のようなエラーが出た。

> hogehoge@0.1.0 build
> next build

info  - Loaded env from /hogehoge/.env.production
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

info  - Checking validity of types...
It looks like you're trying to use TypeScript but do not have the required package(s) installed.

Please install @types/react by running:

	npm install --save-dev @types/react

If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files in your pages directory).

executor failed running [/bin/sh -c npm run build && npm install]: exit code: 1
ERROR: Service 'web' failed to build : Build failed

でも、package.jsonには@types/reactはある。

調べてみたところ、下記のような記事を発見。
create-next-app --ts not recognising @types/react #36085
[TypeScript] nodeが起動しない Please install @types/react ????

バグが起きているっぽい・・・?
@types/reactのバージョンに18.02を使っているとバグが出る!と言う記事をたくさん見かけたのですが
そもそも"^17.0.41"を使用していたのでこれには該当しない(恐らく)

ですが、どうやら他にも、typescriptやnode、nextなど他のバージョンとも関連してバグが起きているようだったので、一旦@types/reactをダウングレードしてバージョンを固定させようと思い、package.jsonを下記のように書き換えました。

package.json
{
  "devDependencies": {
    "@types/react": "17.0.11",
  }
}

npm installを実行して、package-lock.jsonのバージョンも変わっていることを確認。

この状態で再度Dockerのbuildをしたら、無事buildできました🎉

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?