0
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?

【Next.js × Docker】Dockerコンテナで`npm run build`すると`Cannot find module`と言われた時の対処法【備忘録】

Posted at

結論

Module not found: Can't resolve '@/app/hoge/huga/piyo' と言われたら
まず next.config.js でエイリアスを解決してあげる

next.config.json
/** @type {import('next').NextConfig} */
const nextConfig = {
  // デフォルト設定だとこれでいける
  // いじくった人は`alias`を変えて`path.join(__dirname, "src")`てきなことをしてください
  webpack: (config, { isServer }) => {
    config.resolve.alias["@"] = __dirname;
    return config;
  },
};

module.exports = nextConfig;

このままだと Error: Cannot find module 'tailwindcss' とかも言われるので Dockerfileもいじくる

Dockerfile
- RUN npm install
+ RUN npm install --production=false

解決!

参考文献

偉大なる Stackoverflow のコミュニティ

Next.js v13と書かれているが自分の環境ではv14でも起こった
もしかしたら自分のDockerfileの書き方が雑すぎて起きているのかもしれないがとりあえず同じことが起こった人用に

0
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
0
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?