title: Js: Can't import object from external file with node-fetch imported
body: <p>I have some credential saved in a file called <code>secrets.js</code>, in the same folder of the <code>main.js</code> file.
  In the <code>secrets.js</code> file I wrote this:</p>
  <pre><code>const secrets = {}
  secrets.key = &quot;...&quot;
  secrets.discord = &quot;...&quot;
  secrets.cityName = &quot;...&quot;
  module.exports = secrets
  </code></pre>
  <p>In the <code>main.js</code> file I wrote this:</p>
  <pre><code>const secrets = require('./secrets.js')
  const fetch = require('node-fetch')
  
  async function main(){
      console.log(secrets)
  }
  
  main()
  </code></pre>
  <p>If I execute the code i get this error:</p>
  <pre><code>internal/modules/cjs/loader.js:1216
        throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
        ^
  
  Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ./weather/node_modules/node-fetch/src/index.js
  require() of ES modules is not supported.
  require() of ./weather/node_modules/node-fetch/src/index.js from ./weather/main.js is an ES module file as it is a .js file whose nearest parent package.json contains &quot;type&quot;: &quot;module&quot; which defines all .js files in that package scope as ES modules.
  Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove &quot;type&quot;: &quot;module&quot; from ./weather/node_modules/node-fetch/package.json.
  
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1216:13)
      at Module.load (internal/modules/cjs/loader.js:1049:32)
      at Function.Module._load (internal/modules/cjs/loader.js:937:14)
      at Module.require (internal/modules/cjs/loader.js:1089:19)
      at require (internal/modules/cjs/helpers.js:73:18)
      at Object.&lt;anonymous&gt; (./weather/main.js:2:15)
      at Module._compile (internal/modules/cjs/loader.js:1200:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
      at Module.load (internal/modules/cjs/loader.js:1049:32)
      at Function.Module._load (internal/modules/cjs/loader.js:937:14) {
    code: 'ERR_REQUIRE_ESM'
  }
  </code></pre>
  <p>But if I comment this line <code>const fetch = require('node-fetch')</code>:</p>
  <pre><code>const secrets = require('./secrets.js')
  //const fetch = require('node-fetch')
  
  async function main(){
      console.log(secrets)
  }
  
  main()
  </code></pre>
  <p>then it works and I get the expected output:</p>
  <pre><code>{ key: '...', discord: '...', cityName: '...' }
  </code></pre>
  <p>It appears that importing node-fetch is the cause of the error.
  I am using the v16.10.0 of node.
  Can someone help me?</p>