title: Error: Cannot find module '/next', docker, next.js
body: <p>I want to create containers out of my <code>next.js</code> application however I encounter a weird error that I couldn't solve after about 3 days of investigating.</p>
  <p><code>package.json:</code></p>
  <pre><code>{
    &quot;name&quot;: &quot;client&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;&quot;,
    &quot;main&quot;: &quot;index.js&quot;,
    &quot;scripts&quot;: {
      &quot;dev&quot;: &quot;next&quot;,
    },
    &quot;keywords&quot;: [],
    &quot;author&quot;: &quot;Shahin Ghasemi&quot;,
    &quot;license&quot;: &quot;ISC&quot;,
    &quot;dependencies&quot;: {
      &quot;next&quot;: &quot;^9.4.4&quot;,
      &quot;react&quot;: &quot;^16.13.1&quot;,
      &quot;react-dom&quot;: &quot;^16.13.1&quot;
    }
  }
  </code></pre>
  <p><code>Dockerfile:</code></p>
  <pre><code>FROM node:alpine
  COPY package.json .
  RUN npm install
  CMD [ &quot;next&quot;, &quot;run&quot;,&quot;dev&quot; ]
  </code></pre>
  <p>When I run the command <code>docker build -t x/y:tag .</code> it creates the image successfully. however, when I want to run the container it gives me this error:</p>
  <pre><code>$ docker run  abbe27e7cc4d
  internal/modules/cjs/loader.js:1023
    throw err;
    ^
  Error: Cannot find module '/next'
  at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1020:15)
  at Function.Module._load (internal/modules/cjs/loader.js:890:27)
  at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
  at internal/main/run_main_module.js:17:47 {
    code: 'MODULE_NOT_FOUND',
    requireStack: []
  }
  </code></pre>