title: Typescript nodejs Error: Cannot find module './package.json'
body: <p>I am using nodejs 10.1.0</p>
  
  <pre><code>ubuntu@ip-10-0-0-196:~/code/makeIt/chrome-render$ node -v
  v10.1.0
  </code></pre>
  
  <p>I am using typescript2.8.3</p>
  
  <pre><code>ubuntu@ip-10-0-0-196:~/code/makeIt/chrome-render$ tsc -v
  Version 2.8.3
  </code></pre>
  
  <p>I've set up a directory for nodejs development like so:</p>
  
  <pre><code>ubuntu@ip-10-0-0-196:~/code/makeIt/chrome-render$ find
  .
  ./tsconfig.json
  ./node_modules
  . lotsof files in node_modules
  . lotsof files in node_modules
  . lotsof files in node_modules
  ./yarn.lock
  ./src
  ./src/makeIt.ts
  ./src/server.ts
  ./dist
  ./dist/src
  ./dist/src/server.js
  ./dist/src/makeIt.js
  ./dist/src/server.js.map
  ./package.json
  ./dist/src/makeIt.js.map
  ubuntu@ip-10-0-0-196:~/code/makeIt/chrome-render$
  </code></pre>
  
  <p>I compile the code OK with tsc - no errors.</p>
  
  <p>When I run my code I get an error.</p>
  
  <pre><code>ubuntu@ip-10-0-0-196:~/code/makeIt/chrome-render$ node dist/src/server.js
  internal/modules/cjs/loader.js:573
      throw err;
      ^
  
  Error: Cannot find module './package.json'
      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
      at Function.Module._load (internal/modules/cjs/loader.js:497:25)
      at Module.require (internal/modules/cjs/loader.js:626:17)
      at require (internal/modules/cjs/helpers.js:20:18)
      at Object.&lt;anonymous&gt; (/home/ubuntu/code/makeIt/chrome-render/dist/src/server.js:39:20)
      at Module._compile (internal/modules/cjs/loader.js:678:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
      at Module.load (internal/modules/cjs/loader.js:589:32)
      at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
      at Function.Module._load (internal/modules/cjs/loader.js:520:3)
  ubuntu@ip-10-0-0-196:~/code/makeIt/chrome-render$
  </code></pre>
  
  <p>There is no problem when move package.json into dist/src/</p>
  
  <p>node dist/src/server.js</p>
  
  <pre><code>ubuntu@ip-10-0-0-196:~/code/makeIt/chrome-render$ find
  .
  ./tsconfig.json
  ./node_modules
  . lotsof files in node_modules
  . lotsof files in node_modules
  . lotsof files in node_modules
  ./yarn.lock
  ./src
  ./src/makeIt.ts
  ./src/server.ts
  ./dist
  ./dist/src
  ./dist/src/server.js
  ./dist/src/makeIt.js
  ./dist/src/server.js.map
  ./dist/src/package.json
  ./dist/src/makeIt.js.map
  ubuntu@ip-10-0-0-196:~/code/makeIt/chrome-render$
  </code></pre>
  
  <p>Moving package.json does not seem like the right solution - I think I need it to be in my project root.</p>
  
  <p>Can anyone suggest what should I be doing to avoid this error?</p>
  
  <p>Am I configuring my nodejs/typescript project wrong?</p>